Anton | натяжка блока товары
This commit is contained in:
@@ -6,8 +6,155 @@
|
||||
* @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' => 3,
|
||||
'order' => 'ASC',
|
||||
'orderby'=> 'date',
|
||||
)
|
||||
);
|
||||
|
||||
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><span><?php esc_html_e( 'из WooCommerce', 'twentytwentyfour' ); ?></span></div>
|
||||
<button
|
||||
class="mini-button add-to-cart"
|
||||
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_file = ABSPATH . 'index3.html';
|
||||
$landing_html = file_exists( $landing_file ) ? file_get_contents( $landing_file ) : false;
|
||||
|
||||
if ( $landing_html ) {
|
||||
$catalog_markup = twentytwentyfour_test1_catalog_markup();
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
?><!DOCTYPE html>
|
||||
<html <?php language_attributes(); ?>>
|
||||
<head>
|
||||
|
||||
Reference in New Issue
Block a user