| Server IP : 104.171.130.249 / Your IP : 216.73.216.146 Web Server : nginx/1.25.5 System : Linux 0dac65491b7e 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : root ( 0) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/html/wp-content/themes/matreshka/ |
Upload File : |
<?php
/**
* Template: Promotions Archive (/promotions/)
* Shows all active + upcoming promotions
*/
get_header();
$today = current_time( 'Y-m-d' );
// Active promotions
$active = get_posts( [
'post_type' => 'promotion',
'posts_per_page' => 50,
'post_status' => 'publish',
'meta_query' => [
'relation' => 'AND',
[ 'key' => '_promo_date_start', 'value' => $today, 'compare' => '<=', 'type' => 'DATE' ],
[ 'key' => '_promo_date_end', 'value' => $today, 'compare' => '>=', 'type' => 'DATE' ],
],
'orderby' => 'meta_value',
'meta_key' => '_promo_date_end',
'order' => 'ASC',
] );
// Recently ended (last 30 days)
$ended = get_posts( [
'post_type' => 'promotion',
'posts_per_page' => 10,
'post_status' => 'publish',
'meta_query' => [
[ 'key' => '_promo_date_end', 'value' => $today, 'compare' => '<', 'type' => 'DATE' ],
[ 'key' => '_promo_date_end', 'value' => date( 'Y-m-d', strtotime( '-30 days' ) ), 'compare' => '>=', 'type' => 'DATE' ],
],
'orderby' => 'meta_value',
'meta_key' => '_promo_date_end',
'order' => 'DESC',
] );
?>
<main class="site-main promo-archive-page">
<div class="container">
<div class="promo-archive-header">
<h1 class="montserrat-bold">Акции и скидки</h1>
<p class="montserrat-medium text-dark-opacity">Выгодные предложения от Матрёшки</p>
</div>
<?php if ( ! empty( $active ) ) : ?>
<div class="promo-archive-grid">
<?php foreach ( $active as $promo ) :
$promo_id = $promo->ID;
$promo_link = matreshka_get_promo_link( $promo_id );
$promo_thumb = get_the_post_thumbnail_url( $promo_id, 'medium_large' );
$promo_end = get_post_meta( $promo_id, '_promo_date_end', true );
$badge_text = get_post_meta( $promo_id, '_promo_badge_text', true );
$badge_color = get_post_meta( $promo_id, '_promo_badge_color', true ) ?: '#A92231';
$short_desc = get_post_meta( $promo_id, '_promo_short_description', true );
$days_left = matreshka_promo_days_left( $promo_end );
$date_label = matreshka_promo_date_label( $promo_end );
if ( ! $promo_thumb ) {
$promo_thumb = get_template_directory_uri() . '/assets/img/discounts.png';
}
?>
<a href="<?php echo esc_url( $promo_link ); ?>" class="promo-archive-card">
<div class="promo-archive-card-img">
<img src="<?php echo esc_url( $promo_thumb ); ?>" alt="<?php echo esc_attr( get_the_title( $promo_id ) ); ?>">
<?php if ( $badge_text ) : ?>
<span class="promo-badge montserrat-bold" style="background-color:<?php echo esc_attr( $badge_color ); ?>;"><?php echo esc_html( $badge_text ); ?></span>
<?php endif; ?>
<?php if ( $days_left <= 3 && $days_left > 0 ) : ?>
<span class="promo-badge-urgent montserrat-bold">🔥 <?php echo $days_left; ?> дн.</span>
<?php endif; ?>
</div>
<div class="promo-archive-card-body">
<span class="promo-archive-date montserrat-medium text-dark-opacity"><?php echo esc_html( $date_label ); ?></span>
<h3 class="montserrat-bold"><?php echo esc_html( get_the_title( $promo_id ) ); ?></h3>
<?php if ( $short_desc ) : ?>
<p class="montserrat-medium"><?php echo esc_html( $short_desc ); ?></p>
<?php endif; ?>
</div>
</a>
<?php endforeach; ?>
</div>
<?php else : ?>
<div class="promo-empty">
<div class="promo-empty-icon">🎪</div>
<h3 class="montserrat-bold">Сейчас нет активных акций</h3>
<p class="montserrat-medium text-dark-opacity">Но скоро появятся новые! Следите за обновлениями.</p>
<a href="<?php echo esc_url( home_url() ); ?>" class="btn btn-red-primary montserrat-bold">На главную</a>
</div>
<?php endif; ?>
<?php if ( ! empty( $ended ) ) : ?>
<div class="promo-archive-ended">
<h2 class="montserrat-bold">Завершённые акции</h2>
<div class="promo-archive-ended-grid">
<?php foreach ( $ended as $promo ) :
$promo_id = $promo->ID;
$promo_thumb = get_the_post_thumbnail_url( $promo_id, 'medium' );
$short_desc = get_post_meta( $promo_id, '_promo_short_description', true );
if ( ! $promo_thumb ) $promo_thumb = get_template_directory_uri() . '/assets/img/discounts.png';
?>
<div class="promo-archive-card promo-archive-card--ended">
<div class="promo-archive-card-img">
<img src="<?php echo esc_url( $promo_thumb ); ?>" alt="<?php echo esc_attr( get_the_title( $promo_id ) ); ?>">
<span class="promo-badge-ended montserrat-bold">Завершена</span>
</div>
<div class="promo-archive-card-body">
<h3 class="montserrat-bold"><?php echo esc_html( get_the_title( $promo_id ) ); ?></h3>
<?php if ( $short_desc ) : ?>
<p class="montserrat-medium text-dark-opacity"><?php echo esc_html( $short_desc ); ?></p>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<?php
// Get products on sale before rendering the section so an empty block is not shown.
$sale_products = new WP_Query( [
'post_type' => 'product',
'posts_per_page' => 8,
'no_found_rows' => true,
'meta_query' => [
[
'key' => '_sale_price',
'value' => 0,
'compare' => '>',
'type' => 'NUMERIC',
],
],
] );
?>
<?php if ( $sale_products->have_posts() ) : ?>
<!-- section-products - Акции -->
<section>
<div class="container mb-5">
<div class="container-interesting">
<h2 class="montserrat-bold text-red-secondary">
Акции 🔥
</h2>
<div class="product-cards container-products">
<?php
while ( $sale_products->have_posts() ) :
$sale_products->the_post();
global $product;
$product_id = get_the_ID();
$product_link = get_permalink();
$product_image = wp_get_attachment_image_url( $product->get_image_id(), 'woocommerce_thumbnail' );
$product_title = get_the_title();
$weight = $product->get_weight();
$weight_text = $weight ? $weight . 'г' : '200г';
$is_liked = matreshka_is_in_wishlist( $product_id );
$like_icon = $is_liked ? get_template_directory_uri() . '/assets/icons/Heart.svg' : get_template_directory_uri() . '/assets/icons/like.svg';
?>
<div class="product-card" data-product-id="<?php echo esc_attr( $product_id ); ?>">
<a class="link-product" href="<?php echo esc_url( $product_link ); ?>">
<div class="product-card-img">
<?php echo matreshka_get_product_card_image_html( $product, $product_title ); ?>
</div>
<p class="montserrat-medium"><?php echo esc_html( $product_title ); ?></p>
<span class="montserrat-medium"><?php echo esc_html( $weight_text ); ?></span>
</a>
<div class="product-card-bottom">
<?php echo matreshka_get_product_price_html( $product ); ?>
<img src="<?php echo esc_url( $like_icon ); ?>" alt="like icon" class="like-icon <?php echo $is_liked ? 'active' : ''; ?>">
</div>
<button class="btn w-100 btn-secondary montserrat-bold add-to-cart-btn" data-product_id="<?php echo esc_attr( $product_id ); ?>" data-product_sku="<?php echo esc_attr( $product->get_sku() ); ?>">
В корзину
</button>
</div>
<?php
endwhile;
wp_reset_postdata();
?>
</div>
</div>
</div>
</section>
<?php endif; ?>
</div>
</main>
<?php get_footer(); ?>