Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert product in cart through rest api provided by woocommerce?

i am converting a woocommerce store into phonegap app. Now i am stuck. how to add product into cart and display cart into the phonegap app. So how to do it with the help of rest api.

Thanks in advance

like image 663
Sanjay Rathod Avatar asked Apr 16 '14 14:04

Sanjay Rathod


People also ask

How do I add items to my cart in WooCommerce?

In this function, we are fetching the cart items using $woocommerce->cart->get_cart() and checking if the free product is present in the cart or not. If not then add it to the cart using WC()->cart->add_to_cart() function else don't do anything. We can also use template_redirect action hook.

How do I use WooCommerce REST API?

1) Enabling WooCommerce REST API AccessStep 1: Log in to the backend of your WordPress website. Step 2: Hover over “WooComerce”, select “Settings”, and then “Advanced”. Step 3: Toggle the “Legacy API” tab and activate the “Enable the legacy REST API” button. The WooCommerce API is now enabled.

How do I add something to my cart page in WordPress?

Go to WooCommerce » Settings and then click on the 'Advanced' tab. After that, select the new cart page URL that you created with SeedProd. Make sure to click 'Save changes' at the bottom of the screen. Depending on the WooCommerce theme you're using, your visitors can now navigate to the cart page easier.


2 Answers

This related GitHub issue might help.

It seems that there will be no API for sessions or cart. It is suggested to use the order endpoint if you want to use the API. There is a way to add a product to the cart without the API though, you can do that with an URL like: http://yourproducturl.com/checkout/?add-to-cart=%ID%.

like image 71
Martin van Driel Avatar answered Oct 19 '22 04:10

Martin van Driel


on Wordpress 5.4.1, Woocommerce 4.1.0 you have endpoints under this namespace for managing cart and others

https://yoursite.com/wp-json/wc/store/

check it out.

like image 41
tewshi Avatar answered Oct 19 '22 02:10

tewshi