Discount functions
How a NERD Functions discount works: rule structure, condition fields, target selection, value types, discount classes, combinations, and eligibility.
What it is
A discount function is a Shopify automatic discount whose logic is a list of rules instead of one of Shopify’s built-in discount types. It runs in checkout’s discount generation step, so it applies in the cart, checkout, draft orders that use automatic discounts, and POS, for every way an item reached the cart.
Rule structure
Each rule has:
- Discount class: product, order, or shipping.
- Conditions: a group joined by AND or OR, each on a field, an operator, and a value.
- Targets (product discounts): which matched lines to discount, with target selection all, cheapest matching, or most expensive matching, and an optional target quantity.
- Value: percentage, fixed amount, fixed price for the targeted lines, or fixed price per unit.
Up to ten rules per function. Rules are evaluated in order; a line takes the best value among the rules that match it.
Condition fields
| Group | Fields |
|---|---|
| Line | quantity, product id, variant id, product collections, product tags |
| Cart | cart total, cart attribute, sales channel |
| Custom data | product metafield, variant metafield, shop metafield, line item property |
| Aggregates | line count, quantity sum, and amount sum per collection, tag, product, variant, property, or metafield |
| Metaobjects (Advanced) | fields of synced metaobject entries |
Operators cover equality, comparison, contains, is one of, exists, and their negations. Values can be literals, or on the Advanced plan, variables.
Settings on the function
- Combines with: product, order, and shipping discounts, the same model as native discounts. Stacking several discounts on one line is a Shopify Plus capability.
- Eligibility: everyone, customer segments, or markets.
- Tags and title: how the discount appears in checkout and in order details.
Where the config lives
Saving writes the rules as $app metafields on the automatic discount in your store. The Function reads them at checkout. Nothing about your discounts is evaluated on the app’s servers.
Updated