A line_item represents a single line in the cart. There is one line item in the cart for each distinct product variant. The line_item object is available in all Liquid templates through cart.items, in email notification templates through line_items, on the order status page of the checkout, and in apps such as order printers.

Money attributes such as prices and totals are returned in the customer's local (presentment) currency. Use a money filter to show the result as a money amount.

The line_item object has the following attributes:

lineitem.discountallocations

Returns a list of all discount allocations, each with the discounted amount and a reference to the parent discount application. line_item.discount_allocations is available for line items in carts, checkouts, orders and draft orders.

lineitem.finalline_price

Returns the combined price of all items in the line item. This equals line_item.final_price times line_item.quantity.

lineitem.finalprice

Returns the price of the line item including all line-level discounts.

line_item.fulfillment

Returns the fulfillment of the line item.

lineitem.fulfillmentservice

Returns the fulfillment service of the line item's variant. Line items without a fulfillment service return manual.

lineitem.giftcard

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

line_item.grams

Returns the weight of the line item.

Use the weightwithunit filter to format the weight.

line_item.id

Returns the line item ID.

The ID depends on the context:

  • cart.items returns the ID of the line item's variant. This ID is not unique and can be shared by several items of the same variant.
  • checkout.line_items returns a temporary unique hash generated for the checkout.
  • order.line_items returns a unique integer ID.

line_item.image

Returns the image of the line item.

You can apply the image_url filter directly to the line item instead of its image attribute. This creates a working image URL for any object with an image attribute (variant, product, article, collection), an image object or an image src. For line items this is useful because it returns the variant image, or the product image if there is no variant image.

The output is the same whether you use image_url on line_item or on line_item.image.

{{ line_item.image | image_url: width: 100, height: 100 | image_tag: srcset: nil }}
{{ line_item | image_url: width: 100, height: 100 | image_tag: srcset: nil }}
<img src="//cdn.versacommerce.de/s/files/1/0159/3350/products/hvt401_red.jpg?v=1398706734&width=100&height=100&crop=center" width="100" height="100">
<img src="//cdn.versacommerce.de/s/files/1/0159/3350/products/hvt401_red.jpg?v=1398706734&width=100&height=100&crop=center" width="100" height="100">

line_item.key

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

{{ line_item.key }}
17285644550:70ff98a797ed385f6ef25e6e974708ca

lineitem.lineleveldiscountallocations

Returns a list of line-specific discount allocations, each with the discounted amount and a reference to the parent discount application.

lineitem.lineleveltotaldiscount

Returns the total amount of all discounts applied to this line item. Discounts added to the cart as a whole are not included.

line_item.message

Returns the discount message if a script applied a discount to the line item.

lineitem.optionswith_values

Returns an array of the selected values from the item's product options.

Show the elements of line_item.options_with_values with a for loop. Each option is a key-value pair with option.name as the option and option.value as the option value.

Use product.has_only_default_variant to check whether the line item has only a default variant. If so, do not show variant information, because the product has no custom variant options.

{% unless line_item.product.has_only_default_variant %}
  <ul>
    {% for option in line_item.options_with_values %}
      <li>{{ option.name }}: {{ option.value }}</li>
    {% endfor %}
  </ul>
{% endunless %}
<ul>
  <li>Size: 42mm</li>
  <li>Color: Silver</li>
  <li>Material: Stainless Steel</li>
</ul>

lineitem.originalline_price

Returns the combined price of all items in the line before discounts. This equals line_item.original_price times line_item.quantity.

lineitem.originalprice

Returns the original price of the line item before discounts.

line_item.product

Returns the product of the line item.

lineitem.productid

Returns the ID of the line item's product.

line_item.properties

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

Use line item properties on product pages to collect customization information, for example engraving text.

Collect line item properties on the product page with an input in the product form. The input needs a name attribute with this syntax:

properties[property-name]

For example, this input collects engraving text for a product:

{% form 'product', product %}
  ...
  <label for="engravingText">Engraving</label>
  <input type="text" id="engravingText" name="properties[Engraving]">
  ...
{% endform %}

Start a property name with an underscore to hide it from customers at checkout, for example properties[_hiddenPropertyName].

Output the properties by looping through line_item.properties:

{% unless line_item.properties == empty %}
  <ul>
  {% for property in line_item.properties %}
    <li>{{ property.first }}: {{ property.last }}</li>
  {% endfor %}
  </ul>
{% endunless %}
<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.

lineitem.requiresshipping

Returns true if the line item's variant requires shipping, false otherwise.

lineitem.sellingplan_allocation

Returns a selling_plan_allocation object if the line item has a selling plan. VersaCommerce currently has no selling plans, so this value is empty.

line_item.sku

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

lineitem.successfullyfulfilled_quantity

Returns the quantity of the line item that was fulfilled successfully.

line_item.taxable

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

line_item.title

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

{{ line_item.title }}
Balloon Shirt - M

To output only the product title or the variant title, use the title of the respective object.

Product title: {{ line_item.product.title }}
Variant title: {{ line_item.variant.title }}
Product title: Balloon Shirt
Variant title: M

lineitem.unitprice

Returns the unit price of the line item. The price reflects all discounts applied to the line item.

lineitem.unitprice_measurement

Returns a unitpricemeasurement object for the line item.

line_item.url

Returns the relative URL of the line item's variant. The relative URL does not include the root URL of your shop.

lineitem.urlto_remove

Returns a URL that removes the line item from the cart. Only available for cart line items.

line_item.variant

Returns the variant of the line item.

lineitem.variantid

Returns the ID of the line item's variant.

line_item.vendor

Returns the vendor of the line item's product.

More properties

VersaCommerce also provides these properties on the line_item object:

Properties Returns
instructions, options, extra_price, tax_rate, tax_lines, errors, error_message Editing flags, stored options, price adjustments, tax and validation state