Would it be possible to hide all the products marked as "sale" on the standard WooCommerce shop page?
The sale products will be posted on a separate Sale page.
To hide all on sale products (except variable products) on Woocommerce shop page, use:
add_filter( 'woocommerce_product_query_meta_query', 'on_sale_products_not_in_archives', 10, 2 );
function on_sale_products_not_in_archives( $meta_query, $query ) {
// For woocommerce shop pages
if( is_shop() ){
$meta_query[] = array(
'key' => '_sale_price',
'value' => '',
'compare' => '=',
);
}
return $meta_query;
}
Code goes in function.php file of your active child theme (or theme). Tested and works.
If you need that on all archives pages as product category archive pages and product archive tag pages, use:
if( is_shop() || is_product_tag() || is_product_category() ){
Instead of if( is_shop() ){
…
For variable products it's not possible as we need to check all the product variations of a variable product.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.