line_item

A line_item represents a single line in the shopping cart. There is one line item for each distinct product variant in the cart.

The line_item object can be accessed in all Liquid templates via cart.items, in notification email templates via line_items, on the order status page of the checkout, as well as in apps such as Order Printer.

The line_item object has the following attributes:

line_item.discounts

Returns any discounts that scripts have applied to the line item. Only has a value if you are using the Script Editor app.

line_item.fulfillment

Returns the fulfillment of the line item.

line_item.fulfillment_service

Returns the fulfillment service associated with the line item's variant. Line items that have no fulfillment service will return manual.

line_item.gift_card

Returns true if the line item's product is a gift card, or false if it is not.

line_item.grams

Returns the weight of the line item. Use the weight_with_unit filter to format the weight.

line_item.image

Returns the line item's image.

You can apply the img_url filter directly to the line item instead of its image attribute. This will generate a working image URL for any object with an image attribute (variant, product, line item, collection), image object, or image src. This is useful for line items, since it will output the item's variant image or the product's featured image if no variant image exists.

In the example, note that the output is the same no matter if img_url is used on line_item or line_item.image.

Input

{{ line_item.image | img_url: 'small' | img_tag }}
{{ line_item | img_url: 'small' | img_tag }}

Output

<img src="//cdn.shopify.com/s/files/1/0159/3350/products/hvt401_red_small.jpg?v=1398706734" />
<img src="//cdn.shopify.com/s/files/1/0159/3350/products/hvt401_red_small.jpg?v=1398706734" />

line_item.key

Returns the line item key, a unique identifier for the line item. The line item key is constructed from the line item's variant ID plus a hash of the line item's properties, even if the item has no additional properties.

Input

{{ line_item.key }}

Output

17285644550:70ff98a797ed385f6ef25e6e974708ca

line_item.line_price

Returns the combined price of all the items in the line_item. This is equal to line_item.price times line_item.quantity.

line_item.message

Returns the discount message if a script has applied a discount to the line item. Only has a value if you are using the Script Editor app.

line_item.original_line_price

Returns the original price of the line item before discounts were applied. Only has a value if you are using the Script Editor app.

line_item.original_price

Returns the original price of the line item before discounts were applied. Only has a value if you are using the Script Editor app.

line_item.price

Returns the price of the line item's variant.

line_item.product

Returns the product of the line item.

line_item.product_id

Returns the ID of the line item's product.

line_item.properties

Returns an array of custom information for an item that has been added to the cart.

For more information, see the documentation on customization information for products.

When accessed, line_item.properties array elements will be displayed using a for loop.

Did you know?

The Liquid code first checks to ensure that the line_item.properties array is not empty. If the array is empty, the loop does not run and nothing is printed in the list.

Input

{% unless line_item.properties == empty %}
<ul>
  {% for property in line_item.properties %}
  <li>{{ property.first }}: {{ property.last }}</li>
  {% endfor %}
</ul>
{% endunless %}

Output

<ul>
  <li>Monogram: My dog is the cutest</li>
  <li>Gift wrap: Yes</li>
</ul>

line_item.quantity

Returns the quantity of the line item.

line_item.requires_shipping

Returns true if the variant of the line item requires shipping, or false if it does not.

line_item.sku

Returns the SKU (stock keeping unit) of the line item's variant.

line_item.successfully_fulfilled_quantity

Returns the successfully fulfilled quantity of the line item.

line_item.taxable

Returns true if taxes are charged on the line item's variant, or false if they are not.

line_item.title

Returns the title of the line item. line_item.title combines both the line item's product.title and the line item's variant.title, separated by a hyphen.

Input

{{ line_item.title }}

Output

Balloon Shirt - Medium

To output just the product title or variant title, you can access the title of the respective variables.

Input

Product title: {{ line_item.product.title }}
Variant title: {{ line_item.variant.title }}

Output

Product title: Balloon Shirt
Variant title: Medium

line_item.total_discount

Returns the total amount of all discounts applied to the line item. Only has a value if you are using the Script Editor app.

line_item.url

Returns the relative URL of the line item's variant. The relative URL does not include your store's root URL (mystore.myshopify.com).

line_item.variant

Returns the variant of the line item.

line_item.variant_id

Returns the ID of the line item's variant.

line_item.vendor

Returns the vendor of the line item's product.

line_item.id

Returns the ID of the line item, which is the same as the variant ID of the line item.

Want to discuss this page?

Visit the Shopify Community