Hi, We have complex category stucture on the website and also a lot of categories, therefore it would be very important to show these in two levels. I can setup with the shortcode the listing only of the parent categories on the main shop page, but if I click on any parent category, than I see all of the products within this category. Because of the complex category system, in this case I need to see first all of the clicked parent category related “sub” categories and than the related products. Please be so kind and let me know, how can I setup it? Thank you very much.
The page I need help with: [log in to see the link]
I completely understand the need to display your product categories in a clear two-level structure, especially when working with many categories and subcategories. It definitely helps your customers navigate more easily through your shop.
To achieve this, you can use the WooCommerce Shortcodes to list subcategories separately before showing the products. On your parent category page, WooCommerce by default shows products, but you can adjust this by customizing your theme’s category template or using a shortcode like this:
[product_categories parent="0" columns="4"]
If you want subcategories to appear when a parent category is clicked, you can use:
Hi, Thank you, as I wrote, I know the Show Top Level Categories Only shortcode, as I underrstand, this code will be on the main page of the shop. But unfortunate, I din’t understand the other steps: If you want subcategories to appear when a parent category is clicked, you can use: [product_categories parent=”ID_OF_PARENT_CATEGORY”] How can I use it? I added the first code for the shop page, but if I click on any parent category, than the next page/url lits the products. How will the second suggested shortcode modify it? Honestly, I really surpriced, that tere is no default setup option for this very logical stucture nedd. Thank you very much!
Thank you for getting back to me. To clarify, there is a default option in WooCommerce for what you’re trying to achieve, but it also depends on your theme and whether it supports this feature.
To set this up, go to Appearance → Customize → WooCommerce and make sure your shop page is set to display categories and the category display is set to show subcategories, as shown in the screenshot below:
After that, go to Products → Categories, and edit each of your parent categories to display only subcategories, as shown in the screenshot below. Make sure to choose subcategories instead of the standard option.
Depending on how your theme is designed, it may automatically display categories on the shop page and then show subcategories when a category is clicked. However, WooCommerce by default hides empty categories, so if a category only contains subcategories and no products, it is considered empty and won’t be displayed.
Some themes offer an option to show empty categories under Appearance → Customize → WooCommerce → Product Catalog, while others do not.
The solution is to use code to achieve this. First, you want to display empty categories (categories without products but with subcategories), and second, you need to ensure the count includes subcategories since WooCommerce’s default count only includes products. The code below can help accomplish this.
With this setup, you should be able to achieve your goal. Please note that the second snippet may need some adjustments depending on your theme, but in most cases, it should work. Both snippets can be added to your theme’s functions.php, a child theme, or via a code snippet plugin.