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
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.
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.
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.
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%
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With