Answer the question
In order to leave comments, you need to log in
How to display only promotional products in WooCommerce?
How to display only those products for which there is a promotion?
That is, such goods, which, in addition to the base price, have a sale price.
Answer the question
In order to leave comments, you need to log in
so wp-panda.com/woocommerce_posts/woocommerce-shortco...
loop is much simpler
<ul class="products">
<?php
$product_ids_on_sale = wc_get_product_ids_on_sale();
$args = array(
'post_type' => 'product',
'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();
wc_get_template_part( 'content', 'product' );
endwhile;
} else {
echo __( 'Продуктов не найдено' );
}
wp_reset_postdata();
?>
</ul><!--/.products-->
You can use the shortcode [sale_products per_page="12"] (12 - the number of products per output)
You can use the code:
$args = array(
'post_type' => 'product',
'meta_query' => array(
'relation' => 'OR',
array( // Simple products type
'key' => '_sale_price',
'value' => 0,
'compare' => '>',
'type' => 'numeric'
),
array( // Variable products type
'key' => '_min_variation_sale_price',
'value' => 0,
'compare' => '>',
'type' => 'numeric'
)
)
);
query_posts( $args );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question