Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort products in WooCommerce WordPress JSON API

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?

like image 806
X09 Avatar asked Feb 07 '23 07:02

X09


1 Answers

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

like image 188
BA_Webimax Avatar answered Mar 02 '23 00:03

BA_Webimax