<?php get_header(); /* Template Name: Sales */ ?>
<main class="main-content cf contacts">
<div class="container">
<div class="breadcrumbs">
<?php if (function_exists('yoast_breadcrumb')) yoast_breadcrumb('<div class="breadcrumbs__inner">', '</div>'); ?>
<h2 class="page-title"><?php the_title(); ?></h2>
</div>
<div class="cat-content__inner">
<?php woocommerce_product_loop_start(); ?>
<?php woocommerce_product_subcategories(); ?>
<?php
$product_ids_on_sale = wc_get_product_ids_on_sale();
$args = array(
'post_type' => 'product',
'post_status ' => 'publish',
'posts_per_page' => 20,
'post__in' => array_merge( array( 0 ), $product_ids_on_sale )
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
$price = intval(get_post_meta( get_the_ID(), '_regular_price', true));
$sale = intval(get_post_meta( get_the_ID(), '_sale_price', true));
$difference = $price - $sale;
$discount = intval($difference/$price*100); ?>
<div class="swiper-slide">
<div class="img-wrap">
<a href="<?php the_permalink(); ?>">
<img src="<?php echo the_post_thumbnail_url(); ?>" alt="">
</a>
</div>
<div class="title"> <a href="<?php the_permalink(); ?>"><?php echo the_title('','',false); ?> </a></div>
<?php global $product; ?>
<? if($product->product_type != "variable"){ ?>
<? if($sale) : ?>
<div class="price">
<span class="old-price"><?php echo $price; ?> ₽</span>
<?php echo $sale; ?> ₽
</div>
<?php else : ?>
<div class="price"><?php echo $price; ?> ₽</div>
<?php endif; ?>
<? }
?>
<? if($product->product_type == "variable"){
woocommerce_variable_add_to_cart(); ?>
<a href="" onclick="forms['add_to_cart_form_<?=get_the_ID();?>'].submit()" class="buy">Купить<span class="basket"></span></a>
<? } else { ?>
<a href="<?php echo $product->add_to_cart_url(); ?>" class="buy">Купить<span class="basket"></span></a>
<? } ?>
<?php //woocommerce_template_loop_add_to_cart(); ?>
<?php if($sale) : ?>
<div class="discount-notify">Скидка<span class="discount-size"><?php echo ceil($discount); ?>%</span></div>
<?php endif; ?>
</div>
<?
endwhile;
} else {
echo __( 'Продуктов не найдено' );
}
//wp_reset_postdata();
?>
<?php if(get_field('description')) { ?><div class="page-description">
<?php the_field('description'); ?>
</div><?php } ?>
</div>
</div>
</main>
<?php
woocommerce_product_loop_end();
wp_pagenavi(array( 'query' => $loop ));
get_footer();
?>