What is a Cart Key?
A cart key is what identifies the cart stored in session along with it’s cart data and expiration. The cart key by default, will be a random set of letters and numbers or if the Cart API request is authenticated, it will relate to the user ID of the authenticator instead.Finding the Cart Key
You can find the cart key returned in the cart response calledcart_key and via the returned headers called CoCart-API-Cart-Key once the first API request has been made.
Once you have the cart key, you can then use it to set the cart_key as a global parameter with any of the Cart API routes to load that cart.
Without the cart key set for other Cart API routes, any requests made will not be applied to the appropriate cart session. This is partially important when adding, updating or removing items to and from the cart as such. The same for coupons, fees and other cart related requests made.
Creating a Cart Key Manually
You can create your own cart key but, it cannot be longer than 42 characters as that is the limit for storing the key in the database.HTTP request
/wp-json/cocart/v2/cart?cart_key=mycartkey123
If you do create your own cart key, it is best that you do so when adding the first item to the cart in order to update the correct cart from the start.