1

1. I want to create a filter with adaptive product attributes, in woocommerce.

Example: I am in product category A, I select the value red from the color filter attribute. After this, only red products are shown, but also from this point I need to show in the filters only attributes which only red-color products have.

Any ideas on how to do this?

I tried looping all red products and get their attributes, so I can hide all other unnecessary attributes. Evidently, this solution is not efficient at all.

2. Also, is there any DB query to return "All attributes of products under category A / subcategory AA ..." ?

Clarification:

  • An attribute is a taxonomy and an attribute value is a term.
  • color is taxonomy and red is a term
3
  • Do you mean color is taxonomy and red is a term? Are you using ajax? Commented Jun 17, 2017 at 16:22
  • Yes and yes. I also edited the question.
    – jack
    Commented Jun 17, 2017 at 16:44
  • it would be better if you post some code in your question such as html markup, ajax function etc you have tried or you want. Commented Jun 17, 2017 at 16:54

1 Answer 1

0

The way WordPress handles this by default is not ideal - they provide the WP_Query object - through that, you can add whatever filters you like but there's no easy way I know of to create adaptive filters.

That's one of the reasons I created my Faster Woo Widgets plugin - it does exactly what you're looking for - it lets you create category widgets with either adapative or standard filters - if you choose adaptive, then a category list of 10 items will become, for example, a list of only 2 items once you have selected the colour Red.

https://www.wpintense.com/knowledgebase/adaptive-filters/

The way I handle this code is through my own custom SQL code. It's a join from wp_posts to wp_taxonomies and the related tables from there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.