The following code removes product categories from the WooCommerce Product Category Widget. It goes in your theme’s functions.php file. To remove only one WooCommerce product category, remove the extra ID’s and trailing commas.
UPDATE: A recent comment on this post reminded me that I wanted to update it with information on how this code works. If you take a look at the comments below, you’ll notice some idiots insisting that I “stole” this snippet from some other website. I got a kick out of the douche that tried to make me think he’s someone from Google in an attempt to scare me into removing the post. I mean, come on…are you that lame? Thanks for the laugh at your expense you scared little troll.
Anyway, I thought I’d explain how I came up with this very basic snippet that these people seem to think is so complex and detailed that I must have stolen it. Here you go:
- woocommerce_product_category_widget_args – This filter is applied inside the
wp_list_categories()function in class-wc-widget-product-categories.php on line 226. This means that the values returned by adding the filter are passed into wp_list_categories.
- wp_list_categories() – This function accepts an array of arguments. One of the keys in this array is
'exclude'to exclude specific category IDs from the results.
This code is hooking into the
woocommerce_product_category_widget_args filter, adding a new element to $cat_args with a key of ‘exclude’ and an arrayed value of the IDs to exclude, returning $cat_args and passing it into the
wp_list_categories() function, which, subsequently, adds the ‘exclude’ key to the array and remove those category ID’s from the WooCommerce Product Category Widget.
A bit of personal advice to avoid looking like a total ass-wipe: show some restraint when it comes to accusing someone you don’t know of something you cannot prove.