Hi Jozsef,
Thanks for writing back.
The setup that your website requires involves a couple of steps:
1. First, you'll need a custom function to detect if the current page is an archive for a subcategory for Products.
Please add the following code, at the bottom of your active theme's "functions.php" file:
function is_subcategory($cat_id = null) {
if (is_tax('product_cat')) {
if (empty($cat_id)){
$cat_id = get_queried_object_id();
}
$cat = get_term(get_queried_object_id(), 'product_cat');
if ( empty($cat->parent) ){
return 0;
}else{
return 1;
}
}
return 0;
}
2. Next, go to WP Admin -> Toolset -> Settings and in "Front-end Content" tab, scroll to "Functions inside conditional evaluations" section and add "is_subcategory" in the "Function name" field to register it.
( ref: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-custom-functions-in-conditions/ )
3. Go to WP Admin -> Appearance -> Customize -> WooCommerce -> Product Catalog and select "Show products" for both "Shop page display" and "Category display" options.
4. Create a new view "View to show product cats" from WP Admin -> Toolset -> Views and configure it to show only those "Product Categories" which have no parent, as shown in this screenshot:
hidden link
This view will be used to show only the grandparent categories on the shop page.
5. Open your "Products" archive view ( hidden link ) and remove everything in between "<wpv-loop wrap="4" pad="true"> ... </wpv-loop>" tags and insert the shortcode for the newly created view (from the step 4) after "[wpv-layout-start]".
screenshot: hidden link
Now, your main shop page should be only showing the list of grandparent product categories.
6. Next, create a new WordPress archive view for the "Product categories" taxonomy archive from WP Admin -> Toolset -> WordPress Archives.
screenshot: hidden link
Design this view, how you'd like your products to show, on subcategory archive pages.
7. To show the list of subcategories and not the products, when the parent level product category archive page is showing, duplicate the view "View to show product cats" that was created in step 4 and name the duplicated view as "View to show product sub-cats".
The only way this duplicated view would be different from the original one would be that the "Query Filter" should be set to "Select taxonomy terms whose parent is the current taxonomy archive."
screenshot: hidden link
8. The last step would be to make the WordPress archive view created in step 6, to show this "View to show product sub-cats" view conditionally.
Open the view "Product categories" (step 6) and in the "Output Editor" section, replace:
[wpv-filter-meta-html]
[wpv-layout-meta-html]
With:
[wpv-conditional if="( is_subcategory() eq '1' )"]
[wpv-filter-meta-html]
[wpv-layout-meta-html]
[/wpv-conditional]
[wpv-conditional if="( is_subcategory() eq '0' )"]
[wpv-view name="view-to-show-product-sub-cats"]
[/wpv-conditional]
As a result, on the archive page for the parent category, it will show the list of sub-categories (from a view created in step 7).
And when on the archive page for the subcategory, it will show the products from that subcategory (from a view created in step 6).
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar