隐藏没有任何产品的WooCommerce类别?

时间:2016-12-09 10:08:06

标签: php css wordpress woocommerce

我想禁用其中没有任何产品的类别。这是代码似乎无法正常工作。

放在我的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' );

2 个答案:

答案 0 :(得分:0)

add_filter(' woocommerce_product_categories_widget_args',' wpsites_exclude_product_cat_widget');

function wpsites_exclude_product_cat_widget($ args){

$ args ['排除'] =数组(' 16',' 46');

返回$ args; }

试试这个

答案 1 :(得分:0)

您可以通过以下方式隐藏特定类别:

add_action( 'pre_get_posts', 'uw_remove_product_cats_shop_page' );
function uw_remove_product_cats_shop_page( $query ) {

    // Comment out the line below to hide products in the admin as well
    if ( is_admin() ) return;

    if ( is_shop() && $query->is_main_query() ) {

        $query->set( 'tax_query', array(
            array(
                'taxonomy' => 'product_cat',
                'field' => 'ID',
                'terms' => array( 200, 205, 210 ), //ID of categories here
                'operator' => 'NOT IN'
            )
        ) );

    }

}
相关问题