Learn how to create a cart
/wp-json/cocart/v2/products
. This returns products in JSON format and shows product IDs and pricing information:
/wp-json/cocart/v2/cart/add-item
route. This will either add the item to the cart, returning the new updated cart object, or return an error response if something went wrong.
/wp-json/cocart/v2/cart/add-item
endpoint with various products.To add one product multiple times to the cart, simply adjust the quantity parameter of the /wp-json/cocart/v2/cart/add-item
endpoint.We recommend using the batch endpoint /wp-json/cocart/batch
when possible to help with the performance of the API as well as provide one complete cart response.cart_key
. The second is via the returned response headers. There you will need to look for CoCart-API-Cart-Key
. In this case the cart key is {cart_key}
.
This cart key is what we need to keep track of the cart session for the guest customer. The reason for that is because we don’t rely on WooCommerce session cookie to store the cart key for us. Doing this allows more freedom for developers and control on how they want to build their headless store.
cart_key
, you must store it somewhere in your application. It can be:
/wp-json/cocart/v2/cart/update?cart_key=<cart_key>&namespace=update-customer
endpoint.
s_
prefix in front to identify the field is for shipping. Followed by setting the field ship_to_different_address
as true.