Answer the question
In order to leave comments, you need to log in
How to get options on category page from all its products in woocommerce?
The site will allow 3 categories of boots shoes bags clothing
allowable boot1 has the option size color and platform
and boot2 has the option size color and platform and also coverage
how to display the list when switching to the boots category
Answer the question
In order to leave comments, you need to log in
Well, if your options are taxonomy attributes, then you can get what you want in 3 SQL queries
- get from the database the IDs of all products belonging to the category (including nested ones, if required)
- get the meta field values _product_attributes
for all IDs from the database.
- go through the array and select the taxonomies that are used in the variations, they are marked with the flag is_variation
.
- Get from the database all the names of the terms of the selected taxonomies for the selected product IDs.
Sample request for the last item
SELECT DISTINCT tr.name
FROM wp_term_relationships ttr
INNER JOIN wp_term_taxonomy AS ttx ON ttx.term_taxonomy_id = ttr.term_taxonomy_id
INNER JOIN wp_terms AS tr ON tr.term_id = ttx.term_id
WHERE ttx.taxonomy IN ('pa_razmer-obuvi-eur') AND ttr.object_id IN (19728)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question