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:
In this tutorial, you'll learn how to display discounts in your theme.
Requirements
Anchor link to section titled "Requirements"You've created a cart template or a customers/order template.
To display discounts in your theme, you'll use the following:
The discount_application
object
Anchor link to section titled "The 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:
- For the cart template:
- For the customers/order template:
The discount_allocation
object
Anchor link to section titled "The 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
.
The line_item
object
Anchor link to section titled "The line_item object"To complete the price display, you need to use price and discount attributes of the line_item
object, including:
Implementing discount displays
Anchor link to section titled "Implementing 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:
The examples in this tutorial use the cart template. However, you can adapt these examples to add discounts to the customers/order template by using the order
object where the cart
object is used.
You can implement the components directly in a Liquid template, or in a section in a JSON template.
Line item discounts
Anchor link to section titled "Line item discounts"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:
Line item price
Anchor link to section titled "Line item price"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:
Line item discounts
Anchor link to section titled "Line item discounts"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:
Cart discounts
Anchor link to section titled "Cart discounts"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.