在商店中隐藏产品类别,但将它们保留在侧边栏上

时间:2021-07-27 16:17:52

标签: php wordpress woocommerce

我找到了下面的代码,它的功能是从商店页面隐藏产品类别,但也从侧边栏隐藏它们。

function get_subcategory_terms( $terms, $taxonomies, $args ) {
 
    $new_terms  = array();
    $hide_category  = array( '294','168','148','154','163','173','159','177', '15' ); // Ids of the category you don't want to display on the shop page
    
      // if a product category and on the shop page
    if ( in_array( 'product_cat', $taxonomies ) && !is_admin() && is_shop()) {

        foreach ( $terms as $key => $term ) {

        if ( ! in_array( $term->term_id, $hide_category ) ) { 
            $new_terms[] = $term;
        }
        }
        $terms = $new_terms;
    }
  return $terms;
}
add_filter( 'get_terms', 'get_subcategory_terms', 10, 3 );


我尝试了很多方法,但都没有将产品类别带回侧边栏。

0 个答案:

没有答案