简体   繁体   English

隐藏Woocommerce商店页面上的所有促销产品

[英]Hide all on sale products on Woocommerce shop page

Would it be possible to hide all the products marked as "sale" on the standard WooCommerce shop page? 是否可以在标准WooCommerce商店页面上隐藏所有标记为“销售”的产品?

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: 要隐藏Woocommerce商店页面上的所有特价商品(可变商品除外) ,请使用:

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). 代码进入您的活动子主题(或主题)的function.php文件中。 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() ){ 代替if( is_shop() ){

For variable products it's not possible as we need to check all the product variations of a variable product. 对于可变产品,这是不可能的,因为我们需要检查可变产品的所有产品变体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM