Skip to main content

updateCart

Adds, updates, or removes cart lines, sets the cart note, applies discount codes, and updates cart attributes. A single call can do more than one of these.

You can use this instead of posting to the cart yourself, so your app doesn't need to know how the cart is rendered. A storefront that configures this action refreshes its own UI. Without a configuration, the default refreshes the cart on themes it recognizes, and reloads the page on themes it doesn't.

A line with merchandiseId is an add, a line with id is an update, and quantity: 0 removes it.

attributes is the complete set of cart attributes the cart should end up with, replacing the existing set rather than merging with it. Leaving out an existing key removes it, and an empty array clears all attributes. The resolved cart doesn't include attributes, so read the set you submitted or fetch it separately.

The call emits the matching cart events as it starts, so they fire whether or not the change succeeds. The lines, note, and attributes events carry a context of standard-action unless you set another. A rejected change resolves with userErrors rather than throwing, so check that array before reading cart.

Adds, updates, or removes cart lines, sets the cart note, or applies discount codes. The call emits the matching cart events as it starts, so they fire whether or not the change succeeds.

Anchor to payload
payload
required
Anchor to options
options

Promise<>
Examples
const { cart, userErrors, warnings } = await Shopify.actions.updateCart({
lines: [{ merchandiseId: 'gid://shopify/ProductVariant/123', quantity: 1 }],
});

if (userErrors?.length) {
showMessage(userErrors[0].message);
return;
}

if (warnings?.length) {
showMessage(warnings[0].message);
}

updateCartCount(cart.totalQuantity);

Was this page helpful?