cart/add

Add products to your cart

Fields

lineItems • [ lineItems ]required

An array of lineItem objects to be added to cart


LineItems Fields

variantIdstring required

The Shopify ID of the variant to add

quantitynumber required

How many to add

sellingPlanIdstring

The Shopify Selling Plan ID for adding a subscription to cart

attributes • [ object ]

An array of Key Value objects that store additional information to the lineItem

Adds one or more products to the shopping cart. This action handles cart creation if no cart exists, processes line items with proper validation, and updates the cart state.

Basic usage - Adding a variant to cart

Tapcart.action("cart/add", {
  lineItems: [
    {
      variantId: '<SHOPIFY_VARIANT_ID>',
      quantity: 1
    }
  ]
});

All cart actions are queued to prevent race conditions and handle multiple sequential updates.


Basic usage - Adding a subscription with a Shopify Selling Plan

Tapcart.action("cart/add", {
  lineItems: [
    {
      variantId: '<SHOPIFY_VARIANT_ID>',
			sellingPlanId: '<SHOPIFY_SELLINGPLAN_ID>',
      quantity: 1
    }
  ]
});

Basic usage - Adding a Line Item attributes

Tapcart.action("cart/add", {
  lineItems: [
    {
      variantId: '<SHOPIFY_VARIANT_ID>',
      quantity: 1,
 			attributes: [{
        key: 'free_gift',
        value: 'true',
      }]	
    }
  ]
});

Use attributes build powerful features on top of cart. Compatible with Shopify Scripts and Functions to build secure backend functionality that relies on line item attributes.