Skip to main content

Cart Line Item API

The Cart Line Item API provides read-only access to a specific line item in the cart. Use this API to get line item details like product information, pricing, discounts, and custom properties. This allows you to build features that respond to the specific item a customer is viewing or interacting with.

  • Line item details: Display detailed information including product details, pricing, and quantities.
  • Item-specific actions: Implement actions based on product type, vendor, or selling plan requirements.
  • Contextual UI: Create interfaces that adapt based on line item characteristics.
  • Discounts and properties: Access discounts, properties, and selling plans for specialized interfaces.

The shopify global object provides read-only access to the current line item in the cart. Access the following properties on shopify to get line item details like product information, pricing, discounts, and custom properties.

Anchor to cartLineItem
cartLineItem
required

The selected line item in the merchant's current cart. Provides complete line item data including product information, pricing, discounts, properties, and metadata. Use for displaying item details and implementing item-specific functionality.


  • Handle optional properties: Check for undefined in optional properties like price, productId, title, sku, and vendor before use.
  • Create contextual experiences: Use line item data to show different interfaces for gift cards, subscriptions, or vendor-specific information.
  • Implement item-specific validation: Use properties like taxable, isGiftCard, and requiresSellingPlan for appropriate business logic.
  • Handle selling plans: When working with subscriptions, check requiresSellingPlan and sellingPlan to provide appropriate subscription management.
  • Access related data efficiently: Use productId and variantId to fetch additional info when needed, but avoid unnecessary API calls.

  • Line item data reflects the current state and may not include real-time inventory, pricing, or selling plan updates until the cart is refreshed.
  • Selling plan information may be limited during refund or exchange operations where digest values aren't available.

Was this page helpful?