QuillObjects
Discount
The discount object for coupons, automatic discounts, and promotional pricing.
The discount object holds a price cut that has been applied to a cart or order. You can read it from cart.discount or from the order.discount_codes array.
Properties
| Property | Type | Description |
|---|---|---|
discount.id | number | The unique discount ID |
discount.name | string | The discount name set in the admin |
discount.code | string | The coupon code (if triggered by code) |
discount.amount | number | The discount value (in the smallest currency unit for fixed amounts, or a percentage) |
discount.type | string | The discount type (see below) |
discount.target_type | string | What the discount applies to: order, products, or shipping |
discount.savings | number | The total savings in the smallest currency unit |
Discount types
| Type | Description |
|---|---|
pct_off_order | Percentage off the entire order |
amount_off_order | Fixed amount off the entire order |
pct_off_products | Percentage off specific products |
amount_off_products | Fixed amount off specific products |
free_shipping | Free shipping |
buy_x_get_y | Buy X get Y free or discounted |
free_gift | Free gift with purchase |
fixed_bundle | Fixed price bundle |
tiered_spend | Spend more, save more |
cheapest_free | Cheapest item free |
Showing applied discounts
On the cart page:
{% if cart.discount %}
<div class="discount-applied">
<p>{{ cart.discount.code }}: {{ cart.discount.savings | money }} off</p>
</div>
{% endif %}On the order confirmation:
{% for discount in order.discount_codes %}
<p>
<span class="discount-code">{{ discount.code }}</span>
<span class="discount-amount">-{{ discount.amount | money }}</span>
</p>
{% endfor %}Conditional content
Show different messaging based on the discount type:
{% if cart.discount %}
{% case cart.discount.type %}
{% when 'free_shipping' %}
<p>Free shipping applied!</p>
{% when 'pct_off_order' %}
<p>{{ cart.discount.amount }}% off your order</p>
{% else %}
<p>Discount applied: {{ cart.discount.savings | money }} off</p>
{% endcase %}
{% endif %}