Skip to content

Instantly share code, notes, and snippets.

@renventura
Last active May 25, 2020 15:12
Show Gist options
  • Save renventura/8c84e03329ba1c06a10c to your computer and use it in GitHub Desktop.
Save renventura/8c84e03329ba1c06a10c to your computer and use it in GitHub Desktop.
Removes an array of product categories from the WooCommerce Product Category Widget.
<?php // Mind this opening php tag
/**
* Remove Categories from WooCommerce Product Category Widget
*
* @author Ren Ventura
*/
//* Used when the widget is displayed as a dropdown
add_filter( 'woocommerce_product_categories_widget_dropdown_args', 'rv_exclude_wc_widget_categories' );
//* Used when the widget is displayed as a list
add_filter( 'woocommerce_product_categories_widget_args', 'rv_exclude_wc_widget_categories' );
function rv_exclude_wc_widget_categories( $cat_args ) {
$cat_args['exclude'] = array('55','68'); // Insert the product category IDs you wish to exclude
return $cat_args;
}
@vishalkakadiya
Copy link

This filter perfectly works .... Thanks Man :) 👍

@princebhalani143
Copy link

princebhalani143 commented Jul 10, 2019

The code only seems to work for the shop page, and not the category pages. Tested With WooCommerce Version: 3.6.5

@renventura
Copy link
Author

@princebhalani143 It seems to be working for me just fine, including on the category pages (also running WC 3.6.5). Can you provide steps for reproducing this?

@princebhalani143
Copy link

@renventura: Thanks for looking into this, I've tried on local host with basic WooCommerce + WordPress + Default theme and it's working smoothly. It's conflict from the Salient theme widget plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment