Я не могу применить приведенный ниже код, когда оба условных тега (is_product_category) вместе на странице категории продукта (и дочернего элемента) и на странице магазина.
Надеюсь, что кто-нибудь может помочь.
Моя цель: каждый продукт страница категории (включая страницу родительской и дочерней категорий), виджет отображает все категории товаров родительского и дочернего (семантичные c связанные) категории (несвязанные категории продуктов, которые необходимо скрыть в виджете).
см. код фрагменты , а также фрагменты кода
//* Used when the widget is displayed as a dropdown
add_filter('woocommerce_product_categories_widget_dropdown_args', 'appliances', 10, 10);
//* Used when the widget is displayed as a list
add_filter('woocommerce_product_categories_widget_args', 'appliances', 10, 10);
function appliances($cat_args) {
if (is_product_category(75) || is_product_category($termchildren)) {
// Create an array that will hold the ids that need to be included
$include_terms = array();
// Push the default term that you need to shown
array_push($include_terms, 75);
// Create an array that will hold the ids that need to be included
$termchildren = get_term_children(75, 'product_cat');
}
if (is_product_category(59) || is_product_category($termchildren)) {
// Create an array that will hold the ids that need to be included
$include_terms = array();
// Push the default term that you need to shown
array_push($include_terms, 59);
// Create an array that will hold the ids that need to be included
$termchildren = get_term_children(59, 'product_cat');
}
foreach($termchildren as $child) {
$term = get_term_by('id', $child, 'product_cat');
array_push($include_terms, $term - > term_id);
}
// Finally pass the array
$cat_args['include'] = $include_terms;
}
return $cat_args;
}