在窗口小部件中排除产品

时间:2017-11-30 12:50:13

标签: php wordpress woocommerce

我想隐藏所有要显示在特定子类别1和小部件中的小部件中的子类别。 3.没有找到任何解决方案。  Woocommerce在下拉列表和小部件中隐藏子类别的产品

主要类别1>子类别1>儿童类别1

儿童类别2子类别2>儿童类别3儿童类别4

主要类别2>子类别3> 5类儿童

儿童类别6子类别4>儿童类别7儿童类别8

add_filter( 'woocommerce_product_categories_widget_args', 'exclude_widget_category' );

  function exclude_widget_category( $args ) {

// Create an array that will hold the ids that need to be excluded
$exclude_terms = array();

// Push the default term that you need to hide 
array_push( $exclude_terms, 80,81,82 );

// Find all the children of that term
$termchildren = get_term_children( 80,81,82, 'product_cat' );

// Iterate over the terms found and add it to the array which holds the IDs to exclude
foreach( $termchildren as $child ) {
    $term = get_term_by( '81', $child, 'product_cat' );     
    array_push( $exclude_terms, $term->term_id );
}

0 个答案:

没有答案