A discount engine on Shopify Functions
Promotional logic was scattered across native discounts and a paid stacking app, with no control over what applied first. I replaced it with one custom Shopify Functions app built from composable rules, and it carried every Black Friday and Cyber Monday phase.
- Role
- Architecture and implementation
- When
- Oct – Nov 2026
The problem
Discounts lived in three places: native automatic discounts, a paid stacking app, and one-off codes. Each sale came with its own ad hoc stacking rules, influencer codes collided with sitewide sales, and nobody could say for sure which discount a customer would get. Meanwhile, native multi-bottle pricing doubled as the control in live A/B tests, so it couldn’t just be ripped out.
The approach
- Rules, not discounts. A JavaScript Shopify Function app with composable pieces: evergreen multi-bottle pricing, sale percentages, product-gated one-time discounts, selectable gifts with purchase, upsell exclusions, and code-stacking controls.
- A written policy first. Promos never stack with each other, they do stack with evergreen bulk pricing, one code per order, first subscription order only. Every future promo inherits it.
- One scheduled discount per sale phase, mirroring the native bulk rates per variant so Shopify simply applies the best offer and tests that remove a discount stay intact.
- Find the edges before customers do. I found that configurations over about 10 KB silently apply nothing, documented it, and slimmed the configs to stay well under it.
- Prove it on a dev store. Every scenario ran on a development store before it touched production.
The outcome
- The engine carried the hero product’s discount cutover and every Black Friday and Cyber Monday 2026 phase.
- The sale ran Black Friday to Cyber Monday to the lifecycle extension with nothing to revert afterward.
- One paid app’s worth of logic is now code we own and can reason about.
Stack
Shopify Functions (JavaScript), the Shopify Admin GraphQL API, and metafield-driven configuration.
Full stack
- Shopify Functions
- JavaScript
- Shopify Admin GraphQL API
- Metafields