Add Product Add-Ons to a cart with the Store API

Add a product with a configured Product Add-Ons field to a WooCommerce cart using the Store API.

Note:

This is a Developer level doc. If you are unfamiliar working with code and resolving potential conflicts, we recommend you work with a Woo Agency Partner for larger projects, or find a WooCommerce developer on Codeable for smaller customizations. We are unable to provide support for customizations under our Support Policy.

For endpoint and field definitions, see the Product Add-Ons REST API reference.

Before you start

↑ Back to top

Use a test store with WooCommerce and Product Add-Ons active. Create a purchasable test product with a short text add-on, and obtain the product ID and add-on ID. This example uses a fresh cart and sends the text Hello. Store API cart writes need a valid Nonce or Cart-Token for that cart session.

Start a cart session

↑ Back to top

Request the cart and keep the cookies. Copy the Nonce response header for the next request; use the same cookie file. Treat the nonce and cookies as private session data.

curl -i -c cookies.txt https://example.com/wp-json/wc/store/v1/cart

Add the configured product

↑ Back to top

Replace PRODUCT_ID, ADDON_ID, and YOUR_NONCE with values from the test store and response. The add-on ID is the key inside addons_configuration.

curl -X POST 'https://example.com/wp-json/wc/store/v1/cart/add-item' \
  -b cookies.txt \
  -H 'Nonce: YOUR_NONCE' \
  -H 'Content-Type: application/json' \
  -d '{
    "id": PRODUCT_ID,
    "quantity": 1,
    "addons_configuration": {
      "ADDON_ID": "Hello"
    }
  }'

Verify and troubleshoot

↑ Back to top

Check the returned cart for the product and the short text add-on value. If the server reports invalid JSON, confirm the numeric product ID is unquoted and remove comments from the JSON. For a missing or invalid nonce, request a fresh cart nonce and reuse the matching session cookies. Confirm the product is purchasable and the add-on ID belongs to it.

Other add-on types accept different values. Use the field type and valid options for your product; this example does not cover file uploads.

Questions and support

↑ Back to top

Something missing from this documentation? Still have questions and need assistance?

  • If you have a question about a specific extension or theme you’d like to purchase, contact us to get answers.
  • If you already purchased this product and need some assistance, get in touch with a Happiness Engineer via our support page and select this product’s name from the Product dropdown.

Related Products

WooCommerce Subscriptions is a WooCommerce extension that lets customers subscribe to your products or...

Add shipment tracking information to your orders.

Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.