2015-09-06 3 views
1

Я использую встроенный виджет категории woocommerce, и на данный момент он отображает как категории, так и подкатегории.Скрыть подкатегории из виджета категории woocommerce

я исключил категорию с помощью этого кода:

add_filter('woocommerce_product_categories_widget_args', 'organicweb_exclude_widget_category'); 
function organicweb_exclude_widget_category($args) { 
// Enter the id of the category you want to exclude in place of '30' 
    $args['exclude'] = array('62'); 
    return $args; 
} 

но виджет все еще показывает это подкатегории.

ссылка: http://tithaty.com.br/?post_type=product

Категория скрыта является Coleções (я настроил в качестве родителя), и я хочу, чтобы скрыть это подкатегории, текущие и те, добавленные в будущем.

Colecao teste является примером подкатегории.

Любые идеи?

Спасибо

ответ

1

Необходимо немного изменить код фильтра. Я добавил комментарии в код, чтобы помочь вам понять, как это работает. Код гарантирует, что существующие подкатегории Coleções и добавленные в будущем всегда будут скрыты.

add_filter('woocommerce_product_categories_widget_args', 'organicweb_exclude_widget_category'); 

function organicweb_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, 62); 

    // Find all the children of that term 
    $termchildren = get_term_children(62, '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('id', $child, 'product_cat');  
     array_push($exclude_terms, $term->term_id); 
    } 

    // Finally pass the array 
    $args['exclude'] = $exclude_terms; 

    return $args; 
} 
Смежные вопросы