Cart API
The Cart API provides endpoints for managing the shopping cart for the current session or logged-in user. All cart operations return the complete cart state, making it easy to keep your frontend synchronized with the server.Overview
The Cart API allows you to:- Retrieve the current cart state
- Add and remove items
- Update item quantities
- Apply and remove coupons
- Update customer billing and shipping addresses
- Select shipping methods
- Calculate taxes and totals
All POST endpoints require either a Nonce Token or a Cart Token for security. GET requests to
/cart do not require authentication.Base Endpoint
All cart endpoints use the base path:Authentication
Nonce Tokens
For traditional WordPress applications, use nonce tokens for write operations:Cart Tokens
For headless applications, use Cart Tokens instead of nonces:Cart-Token response header when you make any request to a cart endpoint. Store this token and include it in subsequent requests.
How to obtain a Cart Token:
- Make a GET request to
/wc/store/v1/cart - Extract the
Cart-Tokenfrom response headers - Use this token for all future cart and checkout operations
When using Cart Tokens, nonce tokens are not required. This makes them ideal for headless implementations where cookies are not available.
Get Cart
Retrieve the current cart state including items, totals, shipping rates, and applied coupons.Request
Response
Response Fields
array
Array of cart items with product details, quantities, and pricing
array
Applied coupon codes and their discount amounts
object
Cart totals including items, fees, shipping, taxes, and discounts
object
Customer shipping address
object
Customer billing address (includes email)
array
Available shipping methods for each package
boolean
Whether cart requires payment
boolean
Whether cart requires shipping
Add Item to Cart
Add a product or variation to the cart.Parameters
integer
required
The product or variation ID to add to cart
integer
required
Quantity to add (must be at least 1)
array
For variable products, an array of attribute objects with
attribute and value keysRequest
Variation Attribute Naming
When adding variations, attribute naming is important: Global Attributes use slugs withpa_ prefix:
- Attribute “Color” →
pa_color - Attribute “Size” →
pa_size
- The attribute name (case-sensitive):
Size,Autograph ✏️ - The attribute slug:
attribute_size,attribute_autograph-%e2%9c%8f%ef%b8%8f
Response
Returns the full cart object (same as Get Cart) on success.Adding Multiple Items (Batch)
To add multiple items in one request, use the batch endpoint:Update Item Quantity
Update the quantity of an existing cart item.Parameters
string
required
The cart item key (from cart response)
integer
required
New quantity (set to 0 to remove item)
Request
Response
Returns the full cart object with updated quantities and totals.Remove Item from Cart
Remove a specific item from the cart.Parameters
string
required
The cart item key to remove
Request
Response
Returns the full cart object without the removed item.Apply Coupon
Apply a discount coupon to the cart.Parameters
string
required
The coupon code to apply
Request
Response
Remove Coupon
Remove a previously applied coupon from the cart.Parameters
string
required
The coupon code to remove
Request
Response
Returns the full cart object with updated totals reflecting the removed coupon.Update Customer Address
Update customer billing and shipping addresses. This recalculates shipping rates and taxes.Parameters
object
Customer billing address object
object
Customer shipping address object (same fields as billing, except no email)
Request
Response
Returns the full cart object with updated addresses, shipping rates, and tax calculations.Select Shipping Rate
Choose a shipping method for a package in the cart.Parameters
integer
required
The package ID (usually 0 for single-package carts)
string
required
The shipping rate ID (e.g., “flat_rate:1”, “free_shipping:2”)
Request
Response
Returns the full cart object with the selected shipping method and updated totals.Error Responses
Standard Error
Conflict Error (409)
When cart state changes during a request, a 409 response includes the current cart:Common Error Codes
Understanding Price Fields
Prices in the Store API are returned as strings representing the smallest currency unit (e.g., cents for USD):Cart Item Keys
Each cart item has a uniquekey (MD5 hash) based on:
- Product ID
- Variation ID (if applicable)
- Variation attributes
- Custom cart item data
Extensions
Theextensions object in responses can contain additional data added by plugins:
Next Steps
Checkout API
Learn how to process checkout and create orders
Store API Overview
Back to Store API introduction