Search code examples
phpwordpresswoocommercecustom-taxonomystorefront

woocommerce storefront excluding categories from homepage


On the storefront homepage template 3 categories are displayed. I can change some aspects, e.g. hide empty and order. What I want to do is either include or exclude specific categories, probably by their id.

function my_edit_storefront_category( $args ) {
    $args['number'] = 10; // works
    $args['exclude'] = "11,22,33"; // doesn't work
    $args['include'] = array(11,22,33); // doesn't work either
    return $args;
}
add_filter('storefront_product_categories_shortcode_args','my_edit_storefront_category' );

Solution

  • The storefront homepage template uses woocommerce 'product_categories' shortcode. This has a limited set of args and some of them are named a bit unusually. There's no exclude arg. You can include categories by id using the 'ids' arg not 'include'.

    function test_storefront_category_filtering( $args ) {
        $args['ids'] = '56,23,26';
        return $args;
    }
    add_filter('storefront_product_categories_shortcode_args','test_storefront_category_filtering' );