Liquid Template Variables - line item
From Spiffy Stores Knowledge Base
A line item represents a single line in the shopping cart.
There is one line item for each distinct product variant being purchased, regardless of the quantity of that variant in the cart. It is important to include the line item's quantity whenever displaying the item to the user. Line items can be accessed from any theme or email template which makes a cart or order object available.
Line items used in the following theme and email templates:
- cart.liquid
- Order Confirmation
- New Order Notification
- New Order Notification (mobile)
- Shipping confirmation
- Shipping update
- Additional Content & Scripts
Contents
- 1 line_item.id
- 2 line_item.cart_index
- 3 line_item.variant
- 4 line_item.product
- 5 line_item.title
- 6 line_item.extended_title
- 7 line_item.extended_options
- 8 line_item.price
- 9 line_item.quantity
- 10 line_item.grams
- 11 line_item.properties
- 12 line_item.line_price
- 13 line_item.tax
- 14 line_item.discount
- 15 line_item.sku
- 16 line_item.note
- 17 line_item.taxable
- 18 line_item.back_ordered
- 19 line_item.url
- 20 line_item.image
line_item.id
Returns the unique internal id of the line item.
This is normally only for internal usage and is only available for order line items.
line_item.cart_index
Returns a unique cart index number for the line item. This index number allows you to refer to a specific line item in the cart, even when there are other line items for the same variation.
This is only available for cart line items.
This variable is used in the cart.liquid
template instead of line_item.variant.id
that was previously used. The change is necessary as the cart now supports unique line items so that items with custom notes attached are added as unique line items. Obviously they all have the same value for line_item.variant.id
, so this new index is used instead.
line_item.variant
Returns the product variant for this line item.
line_item.product
Returns the product for this line_item.
For example, this code retrieves a line item's image:
{{ item.product.featured_image | product_img_url | img_tag }}
line_item.title
Returns the title of this line item.
This is equal to the original product's title, for example, "Balloon Shirt". If the product has more than one variant, then the name of the variant will be appended to the title. So if the "Balloon Shirt" has two variants, "Medium" and "Large", then line_item.title will be "Balloon Shirt - Medium" or "Balloon Shirt - Large". If a "Yellow Flower Baseball Cap" product only has one variant called "Default" then its line_item.title would just be "Yellow Flower Baseball Cap".
line_item.extended_title
Returns the title of this line item, without any additional variant option descriptions.
The additional variant option descriptions are available in line_item.extended_options.
line_item.extended_options
Returns a hash of all variant option descriptions.
<ul> {% for option in line_item.extended_options %} <li>{{ option.first }}: {{ option.last }}</li> {% endfor %} </ul>
line_item.price
Returns the single price of an item in this line item.
line_item.quantity
Returns the quantity of items are represented by this line item.
line_item.grams
Returns the total weight of the items described by this line item in grams. You can format this for viewing by using the weight_with_unit filter.
line_item.properties
Returns an array of properties that have been added to the line item when it was added to the cart, and are used to store custom information about that line item.
For more information, see the tutorial on Asking your customer for additional information.
As line_item.properties returns an array of elements, you will need to access each element of the array using a for loop.
<ul> {% for property in line_item.properties %} <li>{{ property.first }}: {{ property.last }}</li> {% endfor %} </ul>
For example, you might have the following fields defined for your product:
Card Message: Thank you for all your help to set up my Spiffy Store. Gift Wrapping: Yes
line_item.line_price
Returns the combined price of all the items in this line item. This is line_item.quantity times line_item.price less any discounts on the line item.
line_item.tax
Returns the tax that is applicable for this line item.
Currently, tax is not calculated on a line item basis, so the value returned here is always zero.
line_item.discount
Returns the total discount that has been applied to this line item. The discount is calculated from the Shopping Cart Discount rules.
line_item.sku
Returns the SKU of the item's product variant.
line_item.note
Returns the value of the custom note associated with this line item.
line_item.taxable
Returns true
if the line item is taxable and false
if the line item is tax free.
line_item.back_ordered
Returns true
if the line item was out of stock or partially out of stock at the time the order was placed. This flag will only be set if the item is configured to support inventory management and the setting allows the purchase of items even if they are out of stock.
{% if line_item.back_ordered %}This item is back ordered{% endif %}
line_item.url
Return the product page URL associated with this line item, including the variant parameter to enable direct linking to the selected variant.
{{ line_item.title | link_to: line_item.url }} => <a href="/products/cute-dog?variant=9876543">Cute Dog - Brown</a>
line_item.image
Return the image associated with the line item.
As a short-cut, we can apply the img_url filter directly to the line item, rather than using the line_item.image attribute.
{{ line_item.image | img_url: 'small' | img_tag }} produces the same result as {{ line_item | img_url: 'small' | img_tag }}