Reputation: 3956
I am using WooCommerce JSON API on my mobile app but I am having problems sorting the the product list.
This is my url https://www.storeurl.com/wp-json/wc/v1/products
but I don't know which parameters to add to the url to sort the products according to price
, reviews
, rating
and popularity
.
I have read the docs but I couldn't find it. Please do you know I could do this?
Upvotes: 5
Views: 7689
Reputation: 69
After a long search I found solution.
you need to pass query Param like below
https://v1t.a8c.myftpupload.com/wp-json/wc/v3/products? consumer_key=ck_4fxx69xxx195565b4ffca55aca56d2f4d6e&consumer_secret=cs_3928b95d5xxxxxe1e82xx210748956&page=1&status=publish&category=130&per_page=1&orderby=price&order=asc.
Also you can sort by below param.
date, id, include, title, slug, modified, menu_order, price, popularity, rating
Ex: &orderby=popularity, &orderby=rating
if you still facing issue comment here i will help you. Thanks
Upvotes: 3
Reputation: 2679
You just need to append the parameters as part of the query string like so...
https://www.storeurl.com/wc-api/v3/products?orderby=title&order=asc
To take that further, you can use the "Filter" parameter, which allows you to use any WP_Query style arguments you may want to add to your request. So for example, if you wish to sort by "Price", you would do something like...
https://www.storeurl.com/wc-api/v3/products?filter[order]=asc&filter[orderby]=meta_value_num&filter[orderby_meta_key]=_regular_price
Filter - Use WP Query arguments to modify the response; private query vars require appropriate authorization.
Ref: https://woothemes.github.io/woocommerce-rest-api-docs/#list-all-products
Upvotes: 6