Skip to content

Instantly share code, notes, and snippets.

@DxDiagDx
Created April 1, 2021 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DxDiagDx/350feccfa85737dad07178e27deea87a to your computer and use it in GitHub Desktop.
Save DxDiagDx/350feccfa85737dad07178e27deea87a to your computer and use it in GitHub Desktop.
Woo: показать пустые категории без товаров в виджете
//* Used when the widget is displayed as a dropdown
add_filter( 'woocommerce_product_categories_widget_dropdown_args', 'sb_exclude_wc_widget_categories' );
//* Used when the widget is displayed as a list
add_filter( 'woocommerce_product_categories_widget_args', 'sb_exclude_wc_widget_categories' );
function sb_exclude_wc_widget_categories( $cat_args ) {
$term = get_term_by('slug', 'uncategorized', 'product_cat');
if ($term) {
$cat_args['exclude'] = array( $term -> term_id); // category to exclude
// remove category ID from include list if an include list exists
if (isset($cat_args['include'])) {
$includes = wp_parse_id_list($cat_args['include']);
$key = array_search($term->term_id, $includes);
if ( isset($includes[$key]) ) {
unset( $includes[$key] ); // unset the category from include list
}
$cat_args['include'] = implode(', ', $includes);
}
return $cat_args;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment