Created
April 1, 2021 16:06
-
-
Save DxDiagDx/350feccfa85737dad07178e27deea87a to your computer and use it in GitHub Desktop.
Woo: показать пустые категории без товаров в виджете
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//* 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