From this question
WooCommerce: Display ONLY on-sale products in Shop I tried to display product those are discounted. But every time it's displaying all products those are on_sale
.
I also tried _sale_price
meta key. But can't understand how can I solve my problem.
My project output from my code
My $args
variable
$args = array(
'post_type' => 'product',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => '_sale_price',
'value' => 0,
'compare' => '>',
'type' => 'numeric'
)
)
);
I also tried below code. But same result
$args = array(
'post_type' => 'product',
'posts_per_page' => 8,
'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'
)
)
);
Some how I solved my problem. I was wrong when I posted product from admin panel. My code was right. When I posted Product I set price on sale price instead of regular price. Now I removed product sale price those are not discounted. And place that price on regular price. Now My problem solved. This is my output.
My work in admin panel