Update:
i managed to get the titles of the subcategories under the main categories when the main category is clicked, which is allready a step forward.
However when subcategory is clicked, it still shows all the products of the main category instead of only the products in the subcategory.
To give an example:
Before and by default:
only main category possible :snack
when clicked i receive a list of all sandwiches and hamburgers.
What I want to achieve:
Main category: snacks
Subcategories: sandwiches / hamburgers
When you click on snacks, first you get buttons “sandwiches” and “hamburgers” (done ).
If you click on “sandwiches” you get the different sandwich products ( not done 🙂
If you clik on “hamburgers” you get the different hamburger products.( not done 🙂
I receive under each subcategory still the list of all sandwiches and hamburgers.
I presume it has to do with the WPquery in section.tabmenu.php.
But i cannot figure out the correct one for displaying products of subcategories.
Perhaps you guys can give a tip?
Thanks in advance.
Hello @lobodesign,
I was in talk/discussion with the development team.
I have discussed them regarding your requirement and they have provided me with the below code. Hope this will help you.
$parent_id = $product_category->term_id;
$termchildren = get_terms('product_cat',array('child_of' => $parent_id));
foreach($termchildren as $termchild){
$child_cat_id = $termchild->term_id;
$argument = array(
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $child_cat_id,
)
)
);
$child_post = new WP_Query( $argument );
}
Please let us know for any further queries.
Thank you.
Hi there,
thank you for supplying the code,much appreciated.
I will incorporate it in your (adapted) section.tabmenu.php and let you know if it works :-).
Speak soon!