Skip to main content

line_items_for

cart | line_items_for: object
returns array of line_item

Returns the subset of cart line items that include a specified product or variant.

Accepts the following object types:

  • product
  • variant
{% assign product = all_products['bloodroot-whole'] %}
{% assign line_items = cart | line_items_for: product %}

Total cart quantity for product: {{ line_items | sum: 'quantity' }}

Output

Total cart quantity for product: 1
{% assign product = all_products['bloodroot-whole'] %}
{% assign variant = product.variants.first %}
{% assign line_items = cart | line_items_for: variant %}

Total cart quantity for variant: {{ line_items | sum: 'quantity' }}

Output

Total cart quantity for variant: 1
Was this page helpful?