Order WooCommerce Products by Rating - wordpress

In the latest version of Woocommerce API, (the WP REST API v2), the filters have been removed. Earlier I was using the following URL to get products ordered by their average_rating.
products?search=helloWorld&order=desc&filter[orderby]=meta_value_num&filter[orderby_meta_key]=_wc_average_rating
Now since filters have been removed, I am struggling to get the same output without using filters. I could not find anyway to order products according to their rating. I am also aware of the REST Filter Plugin but before going forward that direction, I want to make sure if there is an alternative way.
Any help is highly appreciated.

Change from orderby_meta_key to meta_key
Final code will be as:
products?search=helloWorld&order=desc&filter[orderby]=meta_value_num&filter[meta_key]=_wc_average_rating

Related

Wordpress Woocommerce Sorting

I'm looking for a way to sort the products in our website via most sales (popularity) but I also want to push a few specific and newer products to the top because otherwise it takes ages for users to find them.
There are the two following options
custom/default order
popularity
The issue is that with the custom/default option, it sorts all products that don't have a set priority by the alphabet and not by sales.
Is there a way to use the default sorting but use the popularity sorting unless a priority is set?

How to get bestselling and favorites products in rest API in woocommerce?

I want to get bestselling and favorites products from woocommerce site with rest API .
I read this site but not found any thing about that.
Does it exist any way to get that ?
For People Who are Still Stumbling upon this Question
As per WC v3 API. You can now pull Most Popular products through the API (which is the best selling product list as per my understanding);
GET /wp-json/wc/v3/products?orderby=popularity&order=desc
This should get you the most popular products in descending order by the number of sales. This is not currently documented (as of Feb 2, 2021).
Total list of possible orderby params are: date, id, include, title, slug, modified, menu_order, price, popularity, rating
Another part of the question asks for Favorite product API, which woo commerce doesn't have.
I can see that you can access bestsellers through reports. See here. As for favourites, I think this is done using third party plugins or custom code so I'm not sure how you are going to access this. But if I was to hazard a guess I would probably assume it would be under customer meta

Woocommerce API request returns few products

I have tried to retrieve all the products of a Woocommerce shop using this kind of request, but I only get 10 products:
http://www.mystore.com/wc-api/v3/products?oauth_consumer_key=ck_1234&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1488898708&oauth_nonce=a83kF3&oauth_signature=whatever
The only solution I found is to add a filter in the request in order to get a specific number of products, ex: &filter[limit]=1000. This works fine but the problem is that I need a generic solution because now I want to get products from multiple stores and some of them can have thousands of products.
Is there a better way to get all the products of a store without setting the limit?
OK, it seems that -1 is doing the job: &filter[limit]=-1 or filter%5Blimit%5D=-1
I will add a hint in case someone ends up in the same situation...
if you need to make an API call using Java, make sure you encrypt the above filter together with the rest authorization parameters so as to get the oauth signature.

Best Way to Pass variable to Woocommerce Product?

Here is the setup.
Customer fills out form of information for product specifications. This creates an entry in the db with a unique detailsID.
They then are taken to a product page, with many variables. They select the variable product and checkout.
Now in the db they have an order as well as a separate table with the details of their request.
What is the best way to connect the product they bought with the detailsID?
I would like to basically pass the detailsID to the product page, then add this detailsID to the product. Or add the orderID back into the details table.
I keep going around whether to add this as meta data, or use a session, or just do post order logic to add the order ID back into the details table.
I really just need to link the two once the order completes but am not sure the best method to do this. I am pretty new to Woocommerce so don't know a lot of the hooks yet.
Thank you so much for your suggestions!
After a lot of research and experimenting here is the method I have decided on. This seems to add the information in a variety of places to make it easy to track orders and to insure that the customer is getting the customized product they want.
add custom data to woocommerce
I am using this method very close to how it is spelled out in this great article. This was really helpful for me being a woocommerce newb.

Woocommerce API - Pulling in products, parent_id does not post

I have a woocommerce site setup that is pulling in products from an external system using the woocommerce REST API.
Everything is coming through fine except the parent_id is not being set.
example data:
{"product": {"title":"Example Shoe","type":"simple","status":"publish","regular_price":"84.00","description":"","short_description":"Trainers","categories":["Mens Trainers"],"catalog_visibility":"visible","attributes":[{"name":"Colour","position":1,"visible":true,"variation":false,"options":["BLACK"]}],"images":[{"src":"","title":null,"alt":"","position":0}],"parent_id":5254}}
I'm a bit stumped as to why, and as it is only an integer posting through I can't see why It wouldn't work.
Any help is appreciated,
Thanks.
I figured out after some trial and error that the reason for this is that the parent_id field seems to be used for grouped products so using it for a variable product was causing issues.

Resources