Skip to main content

Cart Lines API

The Cart Lines API provides access to the line items in the buyer's cart during checkout. Use this API to display item details, calculate totals, and modify cart line items.

  • Display cart line item details: Show each item's title, quantity, and price to the buyer.
  • Calculate cart totals: Aggregate quantities or amounts across all line items.
  • Modify cart line items: Add, remove, or update items in the buyer's cart programmatically.
Support
Targets (31)

The shopify global object provides cart line data for the current checkout. Access the following properties on shopify to read the items in the buyer's cart. Available to purchase extension targets.

Anchor to lines
lines
<[]>
required

The list of line items the buyer intends to purchase. Each entry includes the merchandise, quantity, cost, and any custom attributes. Use applyCartLinesChange() to add, remove, or update line items.

Anchor to Cart line item propertiesCart line item properties

The shopify global object provides the following additional properties on shopify for extensions registered for the cart-line-item extension targets.

Anchor to target
target
<>
required

The cart line that this extension is attached to. Use this to read the line item's merchandise, quantity, cost, and attributes.

Available only on the corresponding item target. Shipping option item targets expose shipping option properties; pickup location item targets expose pickup location properties.

Note

Until version 2023-04, this property was a ReadonlySignalLike<PresentmentCartLine>.

The shopify global object provides methods to modify cart line data. Access the following methods on shopify to apply cart line changes. Available to purchase.checkout extension targets.

Anchor to applyCartLinesChange
applyCartLinesChange
(change: ) => Promise<>
required

Adds, removes, or updates line items in the cart. The returned promise resolves when the change has been applied by the server, and the lines property updates with the new state.

Accepts a single change per call. To make multiple changes, call this method separately for each one.

Note

This method returns an error if the cart instruction lines.canAddCartLine is false, or the buyer is using an accelerated checkout method, such as Apple Pay or Google Pay.


  • Read the latest lines before mutating: Cart line IDs aren't stable across updates. Always read the current lines value immediately before passing a line ID to applyCartLinesChange to avoid referencing a stale ID.
  • Check the relevant cart instruction for each operation: The Cart Instructions API exposes lines.canAddCartLine, lines.canRemoveCartLine, and lines.canUpdateCartLine. Check the specific instruction that matches your intended operation.

  • Cart line changes aren't available when the buyer uses an accelerated checkout method such as Apple Pay or Google Pay.

Was this page helpful?