caskew2154
7/22/2019 - 10:31 AM

Hide Categories from Product Categories Sidebar Widget

Allows you to specify an array of categories which will be excluded from the Category Sidebar. Add the Tag ID of the category you want to hide to array on line 3 (e.g. $excludes = array('Tag ID','Tag ID'); )

function exclude_woocommerce_widget_product_categories($widget_args) {
    //Insert excluded category ids here
    $excludes = array(43);
    $includes = explode(",",$widget_args['include']);

    $includes = array_filter($includes, function($value) use ($excludes) {
      return !in_array($value, $excludes);
    });
    $widget_args["include"] = implode(",", $includes);
    return $widget_args;
}
add_filter( 'woocommerce_product_categories_widget_dropdown_args', 'exclude_woocommerce_widget_product_categories');
add_filter( 'woocommerce_product_categories_widget_args', 'exclude_woocommerce_widget_product_categories');