Add attribute/attribute_term filtering to wc_get_products - #65
Open
aines-ldr wants to merge 1 commit into
Open
Conversation
Adds optional attribute/attribute_term params to filter products by WooCommerce global attribute term, using tax_query
Owner
|
Thanks for the PR! Code looks good, tax_query approach + numeric-vs-slug detection + taxonomy_exists() guard are all correct. Two small style fixes before merge:
Push a fixup commit to the same branch and we'll merge. Thanks again. RP Team |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds optional attribute/attribute_term params to filter products by WooCommerce global attribute term, using tax_query
Summary
wc_get_productscurrently supports filtering bycategory,status,type, andsearch, but there's no way to filter by a global WooCommerce attribute (e.g.pa_color) and a specific term (e.g.black-color). This mirrors a filter that already exists in wp-admin (edit.php?taxonomy=pa_color&term=black-color&post_type=product) but isn't exposed through the MCP tool. For stores with many variable products, this makes it impossible for an AI agent to answer "which products use color X" without paginating through every product.Changes
wc_get_productstool schema:attribute(taxonomy slug, e.g.pa_color) andattribute_term(term slug or numeric term_id, e.g.black-color).tax_queryclause and passes it towc_get_products()(WooCommerce's own query helper, which already supportstax_queryviaWP_Query).is_numeric().taxonomy_exists()before querying, throwing a clear exception otherwise.Testing
blackvsblack-color), confirming the term-slug lookup resolves to the exact intended term rather than a fuzzy match.wc_get_productswithout the new params are unaffected.