> For the complete documentation index, see [llms.txt](https://help.pixfizz.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.pixfizz.com/ecommerce/pixfizz-ecommerce/pixfizz-cms/automatic-discounts.md).

# Automatic Discounts

Automatic discounts are cart-level discounts that apply automatically based on formula logic — no promocode required. They work similarly to extra fees but reduce the cart total instead of adding to it.

### Where to configure

Admin → Marketing → Automatic Discounts

### Key rules

* The formula must produce a **positive value** for the discount to be applied. Zero, blank, or negative values are ignored.
* Automatic discounts only apply to **orderline items**. They do not discount extra fees or shipping.
* If the discount amount exceeds the orderlines total, it is **clipped** to the orderlines total. The excess does not carry over to extra fees or shipping. For example: $20 in orderlines + $5 rush fee + $10 shipping, and the formula produces $50 — the discount is capped at $20. The customer still pays $5 + $10 + taxes.
* Automatic discounts stack with promocodes by default. If you want to prevent an automatic discount from applying when a promocode is active, you need to guard it with Liquid (see examples below).
* Automatic discounts are applied **before** extra fees. This means extra fee formulas can see automatic discount values, but automatic discount formulas cannot see extra fees.

### Combining behaviour

By default, automatic discounts **do not combine** with each other. When multiple automatic discounts are configured, the system picks the single discount that produces the largest amount.

If you tick the **"Combines"** checkbox on an automatic discount, it is allowed to combine with other automatic discounts that also have "Combines" enabled. The system automatically evaluates all possible combinations and picks the one that produces the largest total discount.

**Example:**

* Auto discount A: 15%, combines = yes
* Auto discount B: 15%, combines = yes
* Auto discount C: 20%, combines = no
* Auto discount D: 50%, combines = no

The system evaluates:

* A + B combined = 30%
* C alone = 20%
* D alone = 50%

Result: D wins (50% is the largest). But if D were only 25%, the system would pick A + B (30%).

### Formula basics

Automatic discount formulas use the same Ruby expression syntax as extra fee and product pricing formulas, with the same restricted set of cart-level variables:

| Variable              | Description                                                                                |
| --------------------- | ------------------------------------------------------------------------------------------ |
| `orderlines_total`    | Sum of all orderline prices in the cart, before discounts, extra fees, shipping, and taxes |
| `orderlines_discount` | Promocode discount applied to orderlines — does **not** include other automatic discounts  |

These are the **only** pricing variables available. You do not have access to `quantity`, `units`, `pages`, or any other product-level variables — automatic discounts operate at the cart level.

### Liquid in automatic discount formulas

Like extra fees, automatic discount formulas support Liquid. The Liquid is evaluated first, and whatever it outputs is then evaluated as a Ruby pricing expression.

#### Available Liquid variables

| Variable  | Available | Notes                                  |
| --------- | --------- | -------------------------------------- |
| `cart`    | Yes       | With restrictions — same as extra fees |
| `user`    | Yes       | Full access                            |
| `website` | Yes       | Full access                            |

#### Cart properties that do NOT work

Same restrictions as extra fees — these properties can depend on downstream calculations:

* `cart.total`
* `cart.shipping`
* `cart.discount`
* `cart.shipping_discount`
* `cart.tax`

#### Cart properties that DO work

* `cart.orderlines_total`
* `cart.orderlines_discount`
* `cart.promocode_code`
* All non-pricing properties: `cart.custom`, `cart.orderlines`, `cart.address`, `cart.shipping_option`, etc.

### Interaction with extra fees

Automatic discounts are applied **before** extra fees in the calculation order:

1. Orderline prices
2. Promocode discounts
3. **Automatic discounts**
4. Extra fees
5. Shipping
6. Tax

This means extra fee formulas now have access to an additional pricing variable:

| Variable        | Description                                     |
| --------------- | ----------------------------------------------- |
| `auto_discount` | Total amount of all applied automatic discounts |

Extra fee formulas can also use the Liquid variable `cart.auto_discounts` to inspect which specific automatic discount(s) were applied.

### Examples

#### Flat discount on all orders

Discount every order by $5:

```ruby
5
```

#### Percentage discount

10% off the orderline total:

```ruby
orderlines_total * 0.1
```

#### Spend threshold — discount when cart exceeds a value

Give $10 off when the cart orderlines total is $50 or more:

```liquid
{% if cart.orderlines_total >= 50 %}
    10
{% endif %}
```

#### Tiered percentage discount by cart value

Scale the discount percentage based on how much the customer is spending:

```liquid
{%- if cart.orderlines_total >= 200 %}
    orderlines_total * 0.15
{%- elsif cart.orderlines_total >= 100 %}
    orderlines_total * 0.10
{%- elsif cart.orderlines_total >= 50 %}
    orderlines_total * 0.05
{%- endif %}
```

#### Discount for a specific user category

Give wholesale users 20% off automatically:

```liquid
{% if user.category == 'wholesale' %}
    orderlines_total * 0.2
{% endif %}
```

#### Prevent stacking with promocodes

Only apply the automatic discount if the customer has not already entered a promocode:

```liquid
{% if cart.promocode_code == blank %}
    orderlines_total * 0.1
{% endif %}
```

#### Conditional discount based on a cart custom field

Apply a discount when a specific cart custom field value is set (e.g. a loyalty flag):

```liquid
{% if cart.custom.loyalty_member == 'true' %}
    orderlines_total * 0.05
{% endif %}
```

#### Extra fee formula that accounts for automatic discounts

An extra fee that calculates a rush charge on the net orderline value after both promocode and automatic discounts have been applied:

```liquid
{% if cart.custom.rush %}
    (orderlines_total - orderlines_discount - auto_discount) * 0.2
{% endif %}
```
