204 lines
8.7 KiB
PHP
204 lines
8.7 KiB
PHP
<?php
|
||
/**
|
||
* Standalone landing template for the page slug "test1".
|
||
*
|
||
* @package Twenty_Twenty_Four
|
||
* @since Twenty Twenty-Four 1.0
|
||
*/
|
||
|
||
/**
|
||
* Build the catalog markup from WooCommerce products.
|
||
*
|
||
* @return string
|
||
*/
|
||
function twentytwentyfour_test1_catalog_markup() {
|
||
if ( ! class_exists( 'WooCommerce' ) ) {
|
||
return '';
|
||
}
|
||
|
||
$products = wc_get_products(
|
||
array(
|
||
'status' => 'publish',
|
||
'limit' => 4,
|
||
'order' => 'DESC',
|
||
'orderby' => 'popularity',
|
||
)
|
||
);
|
||
|
||
if ( empty( $products ) ) {
|
||
return '';
|
||
}
|
||
|
||
ob_start();
|
||
?>
|
||
<div class="catalog-grid">
|
||
<?php foreach ( $products as $index => $product ) : ?>
|
||
<?php
|
||
$delay_class = $index ? ' reveal-delay-' . $index : '';
|
||
$image_id = $product->get_image_id();
|
||
$image_html = $image_id ? wp_get_attachment_image( $image_id, 'medium', false, array( 'class' => 'catalog-product-image' ) ) : '';
|
||
$short_text = $product->get_short_description();
|
||
if ( '' === trim( wp_strip_all_tags( $short_text ) ) ) {
|
||
$short_text = $product->get_description();
|
||
}
|
||
$short_text = wp_trim_words( wp_strip_all_tags( $short_text ), 22, '...' );
|
||
$price = wp_strip_all_tags( $product->get_price_html() );
|
||
$volume = $product->get_attribute( 'volume' );
|
||
if ( '' === $volume ) {
|
||
$volume = $product->get_attribute( 'pa_volume' );
|
||
}
|
||
if ( '' === $volume ) {
|
||
$volume = __( 'Товар', 'twentytwentyfour' );
|
||
}
|
||
?>
|
||
<article class="catalog-card reveal<?php echo esc_attr( $delay_class ); ?>">
|
||
<?php if ( $image_html ) : ?>
|
||
<div class="catalog-media"><?php echo $image_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
|
||
<?php else : ?>
|
||
<div class="catalog-icon" aria-hidden="true">💧</div>
|
||
<?php endif; ?>
|
||
<h3><?php echo esc_html( $product->get_name() ); ?></h3>
|
||
<p><?php echo esc_html( $short_text ); ?></p>
|
||
<div class="tag-row">
|
||
<span class="chip"><?php echo esc_html( $volume ); ?></span>
|
||
<?php if ( $product->is_in_stock() ) : ?>
|
||
<span class="chip"><?php esc_html_e( 'в наличии', 'twentytwentyfour' ); ?></span>
|
||
<?php endif; ?>
|
||
</div>
|
||
<div class="card-price"><strong><?php echo esc_html( $price ); ?></strong></div>
|
||
<button
|
||
class="mini-button add-to-cart"
|
||
data-product-id="<?php echo esc_attr( (string) $product->get_id() ); ?>"
|
||
data-name="<?php echo esc_attr( $product->get_name() ); ?>"
|
||
data-volume="<?php echo esc_attr( $volume ); ?>"
|
||
data-price="<?php echo esc_attr( (string) wc_get_price_to_display( $product ) ); ?>"
|
||
type="button"
|
||
><?php esc_html_e( 'Добавить в корзину', 'twentytwentyfour' ); ?></button>
|
||
</article>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<?php
|
||
|
||
return (string) ob_get_clean();
|
||
}
|
||
|
||
$landing_template = get_theme_file_path( 'template-parts/test1-landing-static.php' );
|
||
$landing_html = false;
|
||
|
||
if ( file_exists( $landing_template ) ) {
|
||
ob_start();
|
||
require $landing_template;
|
||
$landing_html = (string) ob_get_clean();
|
||
}
|
||
|
||
if ( $landing_html ) {
|
||
$catalog_markup = twentytwentyfour_test1_catalog_markup();
|
||
|
||
ob_start();
|
||
$test1_header_mode = 'cart';
|
||
require get_theme_file_path( 'template-parts/test1-shared-header.php' );
|
||
$shared_header_markup = (string) ob_get_clean();
|
||
|
||
ob_start();
|
||
require get_theme_file_path( 'template-parts/test1-shared-footer.php' );
|
||
$shared_footer_markup = (string) ob_get_clean();
|
||
|
||
if ( '' !== $catalog_markup ) {
|
||
$catalog_static_markup = <<<'HTML'
|
||
<div class="catalog-grid">
|
||
<article class="catalog-card reveal">
|
||
<div class="catalog-icon" aria-hidden="true">💧</div>
|
||
<h3>Вода 19 литров</h3>
|
||
<p>Главный формат для кулеров, кухни и офиса. Самая выгодная цена за литр и удобная возвратная тара.</p>
|
||
<div class="tag-row">
|
||
<span class="chip">хит продаж</span>
|
||
<span class="chip">для кулера</span>
|
||
</div>
|
||
<div class="card-price"><strong>290 ₽</strong><span>за бутыль</span></div>
|
||
<button class="mini-button add-to-cart" data-name="Вода артезианская 19 л" data-volume="19 л" data-price="290">Добавить в корзину</button>
|
||
</article>
|
||
|
||
<article class="catalog-card reveal reveal-delay-1">
|
||
<div class="catalog-icon" aria-hidden="true">🫙</div>
|
||
<h3>Вода 5 литров</h3>
|
||
<p>Удобный домашний формат для кухни, поездок и дачи. Легко хранить, просто переносить.</p>
|
||
<div class="tag-row">
|
||
<span class="chip">домой</span>
|
||
<span class="chip">компактно</span>
|
||
</div>
|
||
<div class="card-price"><strong>95 ₽</strong><span>за бутылку</span></div>
|
||
<button class="mini-button add-to-cart" data-name="Питьевая вода 5 л" data-volume="5 л" data-price="95">Добавить в корзину</button>
|
||
</article>
|
||
|
||
<article class="catalog-card reveal reveal-delay-2">
|
||
<div class="catalog-icon" aria-hidden="true">🥤</div>
|
||
<h3>0.5 / 1.5 литра</h3>
|
||
<p>Для тренировок, поездок, мероприятий и ежедневного запаса питьевой воды дома или на работе.</p>
|
||
<div class="tag-row">
|
||
<span class="chip">спорт</span>
|
||
<span class="chip">мероприятия</span>
|
||
</div>
|
||
<div class="card-price"><strong>39 ₽</strong><span>от 0.5 л</span></div>
|
||
<button class="mini-button add-to-cart" data-name="Питьевая вода 1.5 л" data-volume="1.5 л" data-price="49">Добавить в корзину</button>
|
||
</article>
|
||
|
||
<article class="catalog-card reveal reveal-delay-3">
|
||
<div class="catalog-icon" aria-hidden="true">⛰️</div>
|
||
<h3>Минеральная вода</h3>
|
||
<p>Освежающий вариант для гостей, кафе и тех, кто предпочитает яркий минеральный вкус.</p>
|
||
<div class="tag-row">
|
||
<span class="chip">для кафе</span>
|
||
<span class="chip">рестораны</span>
|
||
</div>
|
||
<div class="card-price"><strong>68 ₽</strong><span>за 1.5 л</span></div>
|
||
<button class="mini-button add-to-cart" data-name="Минеральная вода 1.5 л" data-volume="1.5 л" data-price="68">Добавить в корзину</button>
|
||
</article>
|
||
|
||
<article class="catalog-card reveal reveal-delay-4">
|
||
<div class="catalog-icon" aria-hidden="true">✨</div>
|
||
<h3>Газированная / негазированная</h3>
|
||
<p>Соберите микс под привычки семьи или офиса: мягкая вода на каждый день и газированная к столу.</p>
|
||
<div class="tag-row">
|
||
<span class="chip">микс заказ</span>
|
||
<span class="chip">на выбор</span>
|
||
</div>
|
||
<div class="card-price"><strong>45 ₽</strong><span>за 0.5 л</span></div>
|
||
<button class="mini-button add-to-cart" data-name="Газированная вода 0.5 л" data-volume="0.5 л" data-price="45">Добавить в корзину</button>
|
||
</article>
|
||
</div>
|
||
HTML;
|
||
|
||
$landing_html = str_replace( $catalog_static_markup, $catalog_markup, $landing_html );
|
||
}
|
||
|
||
$landing_html = preg_replace( '/<header class="site-header">.*?<\/header>/is', $shared_header_markup, $landing_html, 1 );
|
||
$landing_html = preg_replace( '/<footer class="footer">.*?<\/footer>/is', $shared_footer_markup, $landing_html, 1 );
|
||
$landing_html = preg_replace( '/<script[^>]+src=["\'](?:\.\/)?index3\.js["\'][^>]*><\/script>/i', '', $landing_html );
|
||
}
|
||
?><!DOCTYPE html>
|
||
<html <?php language_attributes(); ?>>
|
||
<head>
|
||
<meta charset="<?php bloginfo( 'charset' ); ?>">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<?php wp_head(); ?>
|
||
</head>
|
||
<body <?php body_class( 'test1-landing-page' ); ?>>
|
||
<?php wp_body_open(); ?>
|
||
<?php
|
||
if ( $landing_html && preg_match( '/<body[^>]*>(.*)<\/body>/is', $landing_html, $matches ) ) {
|
||
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||
echo $matches[1];
|
||
} else {
|
||
?>
|
||
<main class="site-main" role="main">
|
||
<div style="padding:48px 16px;max-width:1180px;margin:0 auto;">
|
||
<p>Не удалось загрузить шаблон страницы `template-parts/test1-landing-static.php`.</p>
|
||
</div>
|
||
</main>
|
||
<?php
|
||
}
|
||
?>
|
||
<?php wp_footer(); ?>
|
||
</body>
|
||
</html>
|