• Is there any way to show only the subcategories in the shop page?

    The WooCommerce Catalog Settings are already set to show subcategories, but only main categories are shown

    Also any form of nested categories shown would do the job, too (don’t recommend those premium plugins, please. I already know them ?? )

    Mark

Viewing 10 replies - 1 through 10 (of 10 total)
  • hannah

    (@hannahritner)

    In the admin area if you go to woocommerce > settings and select the products tab you can set the Shop Page Display to show subcategories only.
    Hope that works for you!

    Hannah

    What do you mean by “main categories and sub categories”?

    If the shop page shows the top level categories that would be your main ones right?

    Kadence Themes

    Thread Starter Mr.Lovebucket

    (@mrlovebucket)

    @ Hannah: That’s what I did already and it’s not working. That’s why I started this thread.

    @Kadence Themes: You’re right

    Mark

    You can look into just using the woocommerce shortcodes on your site: https://docs.woothemes.com/document/woocommerce-shortcodes/

    There is an option to just add the certain categories.

    Kadence Themes

    Thread Starter Mr.Lovebucket

    (@mrlovebucket)

    Yes, I know. And with the shortcodes on a custom made shop page I managed, that the site looks sort of I want it to be.
    Problem is: WooCommerce shows the top level categories in addition to the categories I display with the shortcodes. If I exclude categories from the shortcodes, subcategories are shown before top level ones and that doesn’t make sense.

    I also tried to hide some categories with the following code added to content-product_cat.php

    if ( is_shop() && in_array( $category->slug, array( 'category_to_hide' ) ) ) {
      return;

    This code hides the categories displayed by WooCommerce and by the shortcodes, so again not the solution I’m looking for.

    Isn’t it so, that WooCommerce should behave in the way Hannah mentioned?

    In the admin area if you go to woocommerce > settings and select the products tab you can set the Shop Page Display to show subcategories only.

    i.e. showing just the subcategories without the top level categories.

    Couldn’t it have something to do with the Virtue theme?

    No it doesn’t have anything to do with the virtue theme, but you welcome to test with a different theme.
    I have to say I don’t really understand what your wanting to do. It seems like you have top level categories that you don’t want? So why not remove? Also with the shortcodes you can exclude certain categories.

    Kadence Themes

    Thread Starter Mr.Lovebucket

    (@mrlovebucket)

    You’re right, it has nothing to do with the theme. I checked it with the fifteen theme and it behaves exactly the same.

    I try to describe my problem more clear:
    I have categories with different structures. Some have just subcats with the manufacturer’s name as their title, others have two or three levels of subcats before that.

    I want the following to appear on the shop page:
    The last subcategories before the manufacturer’s names appear only, i.e. if they are three levels deep, just the subcats in the second last level, if there is just one subcat I want only the top levels to show.
    I managed to hide some top level categories with the code I showed in my last post and show the subcats with the shortcode, but all top level cats appear on the end of the side in a separate row.
    I would like to have the top level cats above everything else.
    I know that it’s just some kind of playing around, but that’s how it is ??

    Honestly I’m not sure what you wanting is possible unless you use a shortcode and specifically exclude everything you don’t want. But woocommerce would know better if there is a why to hook into the results. I would ask on there support form.

    Kadence Themes

    Thread Starter Mr.Lovebucket

    (@mrlovebucket)

    ok, I will try.

    Thank you

    Mark

    Mark,
    Not sure if you still need it. But I think you would use the filter woocommerce_product_subcategories_args. It’s called by woocommerce_product_subcategories() in wc-template-functions.php

    https://hookr.io/filters/woocommerce_product_subcategories_args/

    We’ll need to set Show categories & subcategories for Shop Page Display.

    Below is my code to show subcategories under the Products category:
    add_filter( ‘woocommerce_product_subcategories_args’, ‘pt_woocommerce_product_subcategories_args’, 10, 1 );
    function pt_woocommerce_product_subcategories_args( $array ) {
    $category = get_term_by(‘name’, ‘Products’, ‘product_cat’);
    $parent_id = ($category) ? $category->term_id : 0 ;
    $array[‘parent’] = $parent_id;
    return $array;
    };

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Show only subcategories in shop page – Virtue Theme – WooCommerce’ is closed to new replies.