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?
WPGraphQL allows you to separate your CMS from your presentation layer. Content creators can use the CMS they know, while developers can use the frameworks and tools they love. Query what you need.
This FREE plugin exposes WooCommerce data to WPGraphQL allowing you to interact with your store’s data via GraphQL Queries and mutations. Download the latest release from here or Clone / download the zip of this repository into your WordPress plugin directory, run composer install in plugin directory & activate the WP GraphQL WooCommerce plugin.
Unlike the most common CPTs which use a WP Post object as their data source and a WPGraphQL\Model\Post object as their model, WooGraphQL uses object managers as the data source for the CPTs and each individual has it's own model with it's own set of permissions and restrictions.
GraphQL queries allow access to multiple root resources, and also smoothly follow references between connected resources. While typical a REST API would require round-trip requests to many endpoints, GraphQL APIs can get all the data your app needs in a single request. Apps using GraphQL can be quick even on slow mobile network connections.
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 to Color
(or what ever attribute you want to use)
paColors {
nodes {
id
name
description
colorHex {
hex
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With