Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get shipping rates in woocommerce rest api?

I am using woocommerce-rest-api to create an app of woocommerce site. To create an order in store we have to use create-order api, which requires basic all the order params. So there is a one params called shipping_lines, in which we have to pass shipping id, it's name and shipping rate. So before creating order I called api called list-all-shipping-methods to displays all the shipping method and gives user to select shipping method, which will be pass later to create order. But the problem is that list-all-shipping-methods returning only id, title, description and _links parameters. It not returning the rate of shipping method which I need to pass on create order api.

Can anyone please help me how to get shipping rate so I can pass it to create order ?

like image 326
Kishan Bharda Avatar asked Nov 15 '22 04:11

Kishan Bharda


1 Answers

You can get shipping details including cost by hitting:

https://yourDomain.com/wp-json/wc/v3/shipping/zones/ID/methods/ID

but for this, you'll need zoneID and methodId

  • For Zone ID https://yourDomain.com/wp-json/wc/v3/shipping/zones

  • For method ID https://yourDomain.com/wp-json/wc/v3/shipping/zones/<zoneID>/methods

Now you have the desire zoneID and methodID:

https://yourDomain.com/wp-json/wc/v3/shipping/zones/<zoneID>/methods/<methodID>

And if you want all the shipping methods with cost:

https://yourDomain.com/wp-json/wc/v3/shipping/zones/<zoneID>/methods

NOTE: You should configure shipping details first from your admin panel, otherwise you will not get the desire results.

like image 54
M.Daniyal Aslam Avatar answered Dec 10 '22 18:12

M.Daniyal Aslam