Skip to main content

Discounts

Discounts can be applied at the line item level, or the cart, checkout, or order level. This means that they apply directly to specific line items, or apply to the cart or order as a whole. Discounts can be applied in the following ways:


You've created a cart template or a customers/order template.


To display discounts in your theme, you'll use the following:

Anchor to The ,[object Object], objectThe discount_application object

The discount_application object registers discounts at the cart, checkout, or order level. Depending on where you're implementing your discount display, you'll access the relevant discount applications through the associated parent object:

Anchor to The ,[object Object], objectThe discount_allocation object

The discount_allocation object associates a discount_application with a line item.

You can access an array of all of the discount allocations associated with a line item using line_item.line_level_discount_allocations.

To complete the price display, you need to use price and discount attributes of the line_item object, including:


Anchor to Implementing discount displaysImplementing discount displays

Because discounts can apply to line items or to the cart or order as a whole, you should display discount information in two places:


If a discount applies to specific line items, then it should be displayed with those items. To display discounts with line items, you need to include the following in your display:

If a discount has been applied to a line item, then you should show the original price with a strikethrough, as well as the new discounted price. Each of these can be accessed with the following attributes of the Liquid line_item object:

If a discount has been applied to a line item, then you should show each discount that's applied, with its associated discount amount, or a total discount amount. Line item-specific discounts can be accessed through the line_level_discount_allocations attribute of the Liquid line_item object, and the total line item discount can be accessed through the line_level_total_discount attribute.

The following is an example that outputs the price and discounts display:

{% for line_item in cart.items %}
<!-- line item info -->

{% if line_item.original_price > line_item.final_price %}
<s>{{ line_item.original_price | money }}</s>
{% endif %}

{{ line_item.final_price | money }})

{% if line_item.line_level_discount_allocations.size > 0 %}
Discounts:
<ul>
{% for discount_allocation in line_item.line_level_discount_allocations %}
<li>
{{ discount_allocation.discount_application.title }}-{{ discount_allocation.amount | money }}
</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
Cart page with a shirt added to the cart. A discount applies directly to the shirt line item in the cart.
Tip

For another example of displaying line item discounts, you can refer to Dawn's implementation.


The subtotal is the line item total after line item discounts have applied, and the total is the cart total after cart discounts have applied. If a discount applies to the cart as a whole, then it should display between the subtotal and total.

Cart-level discounts can be accessed through the cart_level_discount_applications attribute of the cart or order object.

Example

Subtotal: {{ cart.items_subtotal_price | money }}

{% if cart.cart_level_discount_applications.size > 0 %}
Discounts:

<ul>
{% for discount_application in cart.cart_level_discount_applications %}
<li>
{{ discount_application.title }}-{{ discount_application.total_allocated_amount | money }}
</li>
{% endfor %}
</ul>
{% endif %}

Total: {{ cart.total_price | money }}
Cart page with a bottle of canola oil added to the cart. A 10% discount applies to the cart as a whole.
Tip

For another example of displaying cart discounts, you can refer to Dawn's implementation.


Was this page helpful?