WooCommerce: Exclude Category from ‘product_categories’ Shortcode
Sometimes solutions are very simple, and you don’t need rocket science to fix your issue!
A client of mine needed to hide a category from the Product Categories Shortcode ([product_categories]); in fact, there is no parameter that allows you to “exclude” a given product category such as “uncategorized” or whatever category you wish.
A rare issue, but once again a quick fix! Here’s how you do it.
1. Find WooCommerce Category IDs
First of all you need a list of all the WooCommerce category IDs in your store. To do so you can proceed in two ways.
The first is purely manual. This is good if you have no more than 20 categories. Go to the Product Categories page, hover on each category “Edit” link and note down the ID which is contained within the URL:
The second method is a little smarter 🙂 You can use PHP in the admin to print a list of category IDs, so you don’t need to worry about doing that manually.
You can use this snippet to print a list of all Category IDs:
2. Exclude the Category IDs from the “product_categories” Shortcode
Now that you have all IDs and the ID of the category you want to hide, simply exclude that from the list of ids inside the shortcode!
// #1 Show all categories
// #2 Show all categories but ID = 8
// ## All category ids: 8, 15, 34, 20, 18, 37, 10
// ## Include all but "8":
[product_categories ids="15, 34, 20, 18, 37, 10"]
This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101
WooCommerce: Display All Products Purchased by User When a WooCommerce customer is logged in, you might want to show them the list of previously purchased products (maybe in a custom “My Account” tab). This is helpful when customers tend to buy the same products over and over again, and therefore you can help them “order again” without having them to search the […]
WooCommerce: How to Remove the “Default Sorting” Dropdown If the WooCommerce product sorting functionality (“Default Sorting” dropdown) is a waste of space or you don’t need that select box at all, you may want to remove it. No matter if you prefer custom code or a simple plugin – hiding the product sorting dropdown is a piece of cake. Enjoy!
WooCommerce: Show “Sold Out” @ Shop Page Here’s another simple snippet that can easily help user experience and make sure a “sold out” badge shows on each out of stock product in the category & shop pages. Not all themes allow this so you can use the snippet below to make it happen!
WooCommerce: Display Out of Stock Products (Shortcode) A client of mine wanted to show out of stock products on a separate page – so I coded a simple shortcode for you all! You can use this shortcode for different goals. For example, you might want to display what products you’ve sold to enhance customer trust / social proof. So let’s see (1) […]
WooCommerce: Display % Discount @ Shop Page Default WooCommerce shows a “Sale” badge if the item is on sale – but what about showing the exact sale percentage instead? I implemented this for one of my freelance clients so here you go with the easy-peasy solution. Enjoy!
Business Bloomer Founder
Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli