I’m using Woo GraphQL and I’m wondering how I should go about getting the color of product attributes. See below for a screenshot of the product attribute in WP Admin:
I’ve tried querying for the top-level pa-
attribute and I’ve tried querying in terms
/termNode
with no luck.
Am I missing something? How do I get this data?
Update: So TIL, that colors in products attributes were actually provided via “Variation Swatches for WooCommerce”. Variation Swatches takes this info and saves it in term meta.
So now my question is a bit different: How do I pull term meta?
2
Answers
You can get term meta using the
get_term_meta()
function. See more here.I believe the meta key you want for this
swatch_id
.The best way that I have found is to not use (or with addition to ) WooSwatches plugin us should use advanced custom fields and WPGraphQL for Advanced Custom Fields in the following way
Taxonomy
is equal toColor
(or what ever attribute you want to use)