WPGraphQL for WooCommerce
This FREE plugin exposes WooCommerce data to WPGraphQL allowing you to interact with your store’s data via GraphQL Queries and mutations.
Community PluginView Plugin on Github
- Install & activate WooCommerce
- Install & activate WPGraphQL
- Clone or download the zip of this repository into your WordPress plugin directory & activate the WP GraphQL WooCommerce plugin.
- (Optional) Install & activate WPGraphQL-JWT-Authentication to add a
loginmutation that returns a JSON Web Token.
- (Optional) Install & activate WPGraphQL-CORS to add an extra layer of security using HTTP CORS and some of WPGraphQL advanced functionality.
- Query your shops products and variations with complex filtering options.
- Query customers, orders, coupons, and refunds (*).
- Manage a customer's session with JWTs and cart/customer queries and mutations(*).
- Create orders manually (*), automatically with the checkout mutation, or pass a customer's session to the WooCommerce checkout page in your theme for complete payment gateway support (#).
(#) This is the recommended method on checkout. You can read it's usage in this excellent write-up by @jacobarriola
Why don't the WooCommerce CPT GraphQL types support all the same features as most WordPress CPTs that WPGraphQL exposes?
The CPTs as well as most of the data objects that WooCommerce defines are wrapped in a object managers distributed by a data store system.
This data store system allows for each individual data object to be defined however needed. What this means is, although by out of the box objects like products, orders, and coupons are defined as WordPress CPTs they don't have to be.
This is what also enables WooCommerce to store most meta connected to these CPTs in separate tables. The object data doesn't even have to be in the same database if the object's data store designed to manage somewhere else, but we are getting out of the scope of this question.
What does all this :pointup: have to do with WooCommerce's CPTs' functionality? Well, the object managers distributed by the data store are WooGraphQL first point of contact for pretty much everything. Unlike the most common CPTs which use a WPPost 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.
This has led to some friction is certain areas of the schema where WooGraphQL support is lacking. I'm sorry for the inconvience, myself and whole WPGraphQL org are working to reduce this friction and WooGraphQL properly integrated with all WPGraphQL + WPGraphQL ACF features.
Thank you for your patience @kidunot89
- Product CRUD mutations.
- And some other stuff I'm sure :thinking_face:
Feel free to test out the extension using this GraphiQL Playground. The playground allows you to execute queries and mutations, as well as view the schema (*).
(*) I have a tendency to forget to update the playground between releases :sweatsmile:, so if you believe this to be the case look me up somewhere on this page and lemme know :manshrugging:
- Sponsor @kidunot89 (WooGraphQL Creator/Developer) on Github
- Sponsor WooGraphQL on OpenCollective
- Sponsor WPGraphQL on OpenCollective
- Sponsor GraphQL-PHP on OpenCollective
- Or Contribute
- Examples with Next.js
- Next.js WooCommerce Theme [source] [demo video]
- Examples with Gatsby
- Gatsby WooCommerce Theme [source] [demo video]
This project exists thanks to all the people who contribute. [Contribute].
Become a financial contributor and help us sustain our community. [Contribute]
Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]