we have a woocommerce shop for bike parts.
Our parent category name is "Motorcycle-Parts". Subcategories are the motorcycle brands, like:
Motorcycle-Parts
=> Suzuki
=> Honda
=> Yamaha
...
Inside the subcategories, we have the products. These products have an attribute called "ccm" (its the cubic capacity,with numeric values).
Now we try to list all existing "ccm" values from the products of each category underneath the category name, like:
Motorcycle-Parts
=> Suzuki
- 300
- 380
- 550
- ...
=> Honda
- 600
- 650
- 700
- ...
=> Yamaha
- 420
- 650
- 860
- ...
So, if for example a product is inside the category "Suzuki" with the attribute pa_ccm (e.g. 500), we want to automatically list that value (500) underneath the category name, so people see, that inside the category Suzuki one (or more) Products exist that have the pa_ccm value 500.
I tried a few things with _get_term_hierarchy, but my skills are limited here. So no results.
Thanks for help and ideas.
2
Answers
So this is what I have now - Working!
This code does list the $term_names from attribute "ccm" underneath the categories and hides duplicate values/term->names.
Last little problem: As we have many products in these categories with alot of attributes and terms, I want to ask if there is a more performand way to optimise that function/query above? Does someone have an idea if its possible to programm that in a way to make the loading time faster?
You may have to loop each category, each product, each attribute and then each term in order to get the desired structure. For the purpose of clarity, I am leaving parent-child category part and presenting rest of the code as below: