i am developing mobile application to connect WooCommerce wordpress V3 rest API in iOS and Android.
i am getting the product list from Rest API
“wp-json/wc/v3/products”
i am able to filter product using
“wp-json/wc/v3/productscategory=241&attribute=pa_flavor&attribute_term=301”
and filter multiple attribute term using
“wp-json/wc/v3/products?attribute=pa_flavor&attribute_term=301,302,305”.
i need to filter product with multiple attribute(like pa_flavor,pa_size,pa_color… etc.) in rest API. how can do that?
2
Answers
I think the question here isn’t how But Why do it that way? And which way is the best approach for you?
What your Describing is basically categories so if that’s the case yes you can.
https://woocommerce.github.io/woocommerce-rest-api-docs/#retrieve-a-product-category
The Request:
curl https://example.com/wp-json/wc/v3/products/categories/9
/wp-json/wc/v3/products/categories/
Now if you want to pull via Attributes
You can Retrieve the Attributes them selves with
/wp-json/wc/v3/products/attributes
I’d ask that you read the Documents on the Woocoomerece Api It’s pretty extensive to be honest.
If you want full control of this. I’d recommend setting categories or Tags and then adding products under said Categories or Tags then pull those tags/Categories
Now you mention your making this for IOS and Android But what framework are you using.
So i can provide you with some actual code examples of this.
Create Custom REST API for Filter Products by multiple attributes
The request:
/wp-json/wp/v3/filter/product/?category=kurtis&filter[pa_color]=XX,X,XXX
For Price:
/wp-json/wp/v3/filter/product/?filter[min_price]=500&filter[max_price]=1000&filter[pa_color]=XX