Hello,
You can try the following code to exclude a specific category from the category widget dropdown:
add_filter( 'woocommerce_product_categories_widget_dropdown_args', 'woo_product_cat_widget_args' );
function woo_product_cat_widget_args( $cat_args ) {
$cat_args['exclude'] = array('10'); // Insert the product category IDs you wish to exclude
return $cat_args;
}
[Code Source]
I would recommend using a plugin like Code Snippets to add the snippet to your site.
-
This reply was modified 4 years, 6 months ago by
MayKato.
Hi @maykato
I tried the code (product category ID is 162) but still not working and the code shows up red when entered:
add_filter( 'woocommerce_product_categories_widget_dropdown_args', 'woo_product_cat_widget_args' );
function woo_product_cat_widget_args( $cat_args ) {
$cat_args['exclude'] = array('10'); // 162
return $cat_args;
}
Any idea what I am doing wrong?
Best,
Chris
Hi @pleazo,
If your product category ID is 162 you may want to use this snippet:
add_filter( 'woocommerce_product_categories_widget_dropdown_args', 'woo_product_cat_widget_args' );
function woo_product_cat_widget_args( $cat_args ) {
$cat_args['exclude'] = array('162'); // Insert the product category IDs you wish to exclude
return $cat_args;
}
To avoid creating problems for anyone who is trying to help here, please add NSFW to the topic title of the post. As per the forum guidelines, this can be used when the content on the site is not suitable for a general audience or for viewing while at work.
If you’re not able to update it you can get assistance from a moderator using the options on the right to report the topic.
Cheers.
Hi @rainfallnixfig
Thanks for your response. Unfortunately, this code is not working.
Some of the code is red (as seen here). This means there’s a problem with the code?
I will set NSFW next time.
Best.
Chris
@pleazo
Kindly confirm if you’re adding the code using CSS customization or the code snippets plugin recommended above. Kindly note the latter is required in this case.
-
This reply was modified 4 years, 6 months ago by
Abiola Ogodo.
-
This reply was modified 4 years, 6 months ago by
Abiola Ogodo.
Hi @oaoyadeyi
I am using the CSS customization.
Best,
Chris
Hi Chris @pleazo
This is actually a PHP snippet so we recommend using a plugin like Code Snippets to add custom PHP code into your site without directly accessing the functions.php file.
Here is a link on how to use the Code Snippets plugin:
https://www.wpbeginner.com/plugins/how-to-easily-add-custom-code-in-wordpress-without-breaking-your-site/
Hope this helps!
Hi there,
We haven’t heard from you in a while, so I’m going to mark this as resolved. Feel free to start a new thread if you have any more questions.