New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store API: Add support to query product_variations by attributes #42983
Store API: Add support to query product_variations by attributes #42983
Conversation
… by attribute slugs
Test Results SummaryCommit SHA: 17204ea
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
Hi @wavvves, Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
Submission Review Guidelines:
Changes proposed in this Pull Request:
Currently you cannot query product variations by attributes using the Store API, despite the documentation saying that it is possible.
In WooCommerce, when querying product variations specifically, the
tax_query
is not used directly because product attributes (like size, color, etc.) associated with variations are stored as post meta, not as taxonomy terms. Hence, you need to usemeta_query
instead oftax_query
when dealing with product variations. Product variations are considered as individual products tied to the main product. These variations hold their specific attributes as meta values in the database, rather than being treated as taxonomy terms.This PR introduces a method which converts the
tax_query
into ameta_query
for typesproduct_variation
only.Known limitation: This will still return no results if you're filtering by attribute ID, in order for this to work you need to pass the attribute slug.
Closes #42093
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
Using the sample products: sample_products.csv
/wp-json/wc/store/v1/products?attributes[0][attribute]=pa_color&attributes[0][slug]=red&type=variation
This should return no results.type=variation
) to confirm this still works as expected and no regression has been introduced.Changelog entry
Significance
Type
Message
Store API: Add support to query
product_variations
by attribute slugs.Comment