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 has the following attributes:
In this article
- line_item.fulfillment
- line_item.grams
- line_item.id
- line_item.image
- line_item.line_price
- line_item.price
- line_item.product
- line_item.product_id
- line_item.properties
- line_item.quantity
- line_item.requires_shipping
- line_item.sku
- line_item.taxable
- line_item.title
- line_item.type
- line_item.url
- line_item.variant
- line_item.variant_id
- line_item.vendor
line_item.fulfillment
Returns the fulfillment of the line item.
line_item.grams
Returns the weight of the line item. Use the weight_with_unit filter to format the weight.
line_item.id
Returns the id of the line item, which is the same as the id of its variant.
line_item.image
Returns the line item image.
For brevity, we can apply the img_url
filter directly to the line item rather than to its image attribute. The img_url
filter can be applied to any object with an image attribute (variant, product, line item, collection), image object, or image src, to generate the appropriate image URL. This is handy for line items where it will output the item's variant image or default to the product's featured_image if no variant image exists.
Input
{{ line_item.image | img_url: 'small' | img_tag }}
<!-- same as -->
{{ line_item | img_url: 'small' | img_tag }}
Output
//hstatic.net/206/1000001206/1/2015/11-10/do__2__2a803876-0037-43b1-7464-dddfaa3d0dce_small.png
//hstatic.net/206/1000001206/1/2015/11-10/do__2__2a803876-0037-43b1-7464-dddfaa3d0dce_small.png
line_item.line_price
Returns the combined price of all the items in the line_item. This is the equivalent of line_item.price
times line_item.quantity
.
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 collecting customization information on the product page.
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
{% assign propertySize = line_item.properties | size %}
{% if propertySize > 0 %}
<ul>
{% for property in line_item.properties %}
<li>{{ property.first }}: {{ property.last }}</li>
{% endfor %}
</ul>
{% endif %}
Output
Monogram: My dog is the cutest
Gift wrap: Yes
line_item.quantity
Returns the quantity of the line item.
line_item.requires_shipping
Returns true
if the line item requires shipping, or false
if it does not. This is set in the variant options in the Products page of the Admin.
line_item.sku
Returns the SKU of the line item's variant.
line_item.taxable
Returns true
if the line item is taxable, or false
if it isn't. This is set in the variant options in the Products page of the Admin.
line_item.title
Returns the title of this 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.type
Returns the product type of the line item's product.
line_item.url
Returns the URL to the product page using variant deep-linking.
Input
{{ line_item.title | link_to: line_item.url }}
Output
<a href="/products/t-shirt?variant=12345678">T-Shirt - Small</a>
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 name of the line item's product.