【问题标题】:Woocommerce - Is it possible to hide a product category based on the stock status of the products that are under this category?Woocommerce - 是否可以根据该类别下产品的库存状态隐藏产品类别?
【发布时间】:2020-12-28 09:57:10
【问题描述】:

我试图从我的商店中隐藏一个类别,因为该类别甚至不包含 1 件库存产品。如果即使有 1 件产品有货,也会显示该类别。

我尝试了类似下面的代码但无济于事:

function hide_out_of_stock_categories( $list_args ){
 if ( ! $product->managing_stock() && ! $product->is_in_stock() ){
            $list_args[ 'hide_empty' ] = 1;
            return $list_args;
}
}

我需要先搜索类别内的产品,然后检查产​​品库存状态是有货还是缺货,但我在这里遗漏了一些东西。

【问题讨论】:

    标签: php wordpress woocommerce hook-woocommerce


    【解决方案1】:

    要隐藏或删除此处列出的空类别,请在主题的 functions.php 文件末尾添加以下代码行。

    function woo_hide_product_categories_widget( $list_args ){
     
          $list_args[ 'hide_empty' ] = 1;
     
          return $list_args;
     
    }
     
    add_filter( 'woocommerce_product_categories_widget_args', 'woo_hide_product_categories_widget' )
    

    【讨论】:

    • 这将隐藏空类别。但我想首先检查该类别中的所有产品是否都处于缺货状态。因此,即使一种产品有库存,该类别也必须保持可见。如果该类别中的所有产品都缺货,则该类别将被隐藏。
    猜你喜欢
    • 2018-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多