Skip to main content
POST
/
cart
/
add-item
Add item to cart
curl --request POST \
  --url {protocol}://{host}/wp-json/cocart/v2/cart/add-item \
  --header 'Content-Type: application/json' \
  --data '
{
  "id": "<string>",
  "quantity": "1",
  "variation": {},
  "item_data": {},
  "email": "jsmith@example.com",
  "phone": "<string>",
  "price": "<string>",
  "return_item": false
}
'
{
  "cart_hash": "e629fa6598d732768f7c726b4b621285",
  "cart_key": "cb7a23af96a3f23af3c28a8b4b8c6d5e",
  "currency": {
    "currency_code": "USD",
    "currency_symbol": "$",
    "currency_symbol_pos": "left",
    "currency_minor_unit": 2,
    "currency_decimal_separator": ".",
    "currency_thousand_separator": ",",
    "currency_prefix": "$",
    "currency_suffix": ""
  },
  "customer": {
    "billing_address": {
      "billing_first_name": "",
      "billing_last_name": "",
      "billing_company": "",
      "billing_country": "",
      "billing_address_1": "",
      "billing_address_2": "",
      "billing_postcode": "",
      "billing_city": "",
      "billing_state": "",
      "billing_phone": "",
      "billing_email": ""
    },
    "shipping_address": {
      "shipping_first_name": "",
      "shipping_last_name": "",
      "shipping_company": "",
      "shipping_country": "",
      "shipping_address_1": "",
      "shipping_address_2": "",
      "shipping_postcode": "",
      "shipping_city": "",
      "shipping_state": ""
    }
  },
  "items": {
    "a3c5e7f9b1d3e5f7a9b1c3d5e7f9a1b3": {
      "item_key": "a3c5e7f9b1d3e5f7a9b1c3d5e7f9a1b3",
      "id": 145,
      "name": "Wireless Bluetooth Headphones",
      "title": "Wireless Bluetooth Headphones",
      "price": "$18.00",
      "quantity": {
        "value": 1,
        "min_purchase": 1,
        "max_purchase": -1
      },
      "totals": {
        "subtotal": 18,
        "subtotal_tax": 0,
        "total": 18,
        "tax": 0
      },
      "slug": "wireless-bluetooth-headphones",
      "meta": {
        "product_type": "simple",
        "sku": "WBH-001",
        "dimensions": {
          "length": "",
          "width": "",
          "height": "",
          "unit": "cm"
        },
        "weight": "0.5",
        "variation": {}
      },
      "backorders": "no",
      "cart_item_data": {},
      "featured_image": "https://example-store.com/wp-content/uploads/2024/03/headphones-blue.jpg"
    }
  },
  "item_count": 1,
  "items_weight": 0.5,
  "coupons": [],
  "needs_payment": true,
  "needs_shipping": true,
  "shipping": {
    "total_packages": 0,
    "show_package_details": true,
    "has_calculated_shipping": false,
    "packages": []
  },
  "fees": [],
  "taxes": [],
  "totals": {
    "subtotal": "18.00",
    "subtotal_tax": "0.00",
    "fee_total": "0.00",
    "fee_tax": "0.00",
    "discount_total": "0.00",
    "discount_tax": "0.00",
    "shipping_total": "0.00",
    "shipping_tax": "0.00",
    "total": "18.00",
    "total_tax": "0.00"
  },
  "removed_items": [],
  "cross_sells": [],
  "notices": {
    "success": [
      "Wireless Bluetooth Headphones has been added to your cart."
    ]
  }
}

Body

application/json
id
string
required

Unique identifier for the product or variation ID.

quantity
string
default:1
required

Quantity of this item to add to the cart.

variation
object

Variable attributes that identify the variation of the item.

item_data
object

Additional item data passed to make item unique.

email
string<email>

Set the customers billing email address.

phone
string

Set the customers billing phone number.

price
string

Overrides the general or sale price with a custom price for the item if set.

return_item
boolean
default:false

Returns the item details once added.

Response

Item added to cart successfully.

Returns a full updated cart response.

cart_hash
string

Unique cart hash.

cart_key
string

Unique cart key for the customer.

currency
object
customer
object
items
object

Cart items indexed by item key.

item_count
integer

Total number of items in cart.

items_weight
number

Total weight of all items.

coupons
object[]

Applied coupons.

needs_payment
boolean

Whether the cart needs payment.

needs_shipping
boolean

Whether the cart needs shipping.

shipping
object
fees
object[]

Cart fees.

taxes
object[]

Cart taxes.

totals
object
removed_items
object[]

Recently removed items that can be restored.

cross_sells
object[]

Cross-sell products.

notices
object

Cart notices and messages.

extensions
object

Additional data from extensions.