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
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
You must be logged in to post a comment.
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.
Some years later, we have a working REST API endpoint at
/wp-json/wc/store/cart/add-item
.It requires a product or variant id and a quantity. It also requires a
X-WC-Store-API-Nonce
header that is set to what wordpress gives you when callingwp_create_nonce('wc_store_api')
. You can even remove items with a negative quantity, neat.Here is a working jQuery example for my variant id 378:
(Tested on WooCommerce 4.5.2, 4.6.1) (Github thread)
Just in case someone finds this, there is CoCart available in the meantime which solves OPs problem:
https://wordpress.org/plugins/cart-rest-api-for-woocommerce/