Search code examples
phpwordpresswoocommercestorefronttaxonomy-terms

Show subcategories of a main category in "Shop By Category" section in Woocommerce Storefront


I'm setting up a Woocommerce shop using Storefront Theme and I would like know how can I show subcategories instead of categories in the "Shop by Category" homepage section?

I need to show product subcategories instead because my root product category is a unique one ("Collection"), and within it I have all the main sub-categories.


Solution

  • Actually you can only display the subcategories of one parent category term ID, which is the case for your "Collection" product category:

    add_filter( 'storefront_product_categories_args', 'custom_storefront_product_categories_args');
    function custom_storefront_product_categories_args( $args ) {
        $args['columns'] = 4; // 4 columns
        $args['limit'] = 8;   // 8 items on 2 rows
        $args['child_categories'] = '18'; // <= The term ID of the main parent category
    
        return $args;
    }
    

    Code goes in function.php file of the active child theme (or active theme). Tested and works.


    Storefront home related: Customize displayed products on Woocommerce Storefront home page