cart/add
Add products to your cart
Fields
lineItems
• [ lineItems ]required
lineItems
• [ lineItems ]requiredAn array of lineItem
objects to be added to cart
lineItem
objects to be added to cartLineItems Fields
variantId
• string required
variantId
• string requiredThe Shopify ID of the variant to add
quantity
• number required
quantity
• number requiredHow many to add
sellingPlanId
• string
sellingPlanId
• stringThe Shopify Selling Plan ID for adding a subscription to cart
attributes
• [ object ]
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.
Updated 9 days ago