Overview
Discount Functions let you create custom discount logic beyond Shopify’s built-in discount types. Volume discounts, bundle pricing, tiered discounts, and customer-specific pricing.How Discount Functions Work
1
Customer Action
Customer adds items to cart or enters checkout
2
Function Execution
Your function receives cart data and evaluates discount logic
3
Discount Applied
Function returns discount configuration
4
Price Updated
Shopify applies discount and updates cart/checkout
Discount Types
Volume Discounts
Discount based on quantity
- Buy 2 get 10% off
- Buy 5 get 20% off
- Tiered pricing
Bundle Discounts
Discount on product combinations
- Buy X + Y get Z free
- Complete the set discount
- Mix and match deals
Customer-Specific
Personalized pricing
- VIP customer discounts
- Loyalty tier pricing
- Wholesale pricing
Conditional Discounts
Context-based pricing
- First-time buyer discount
- Time-based promotions
- Location-based pricing
Example: Volume Discount
Generate a function that gives tiered discounts:1
Describe Your Function
2
Review Generated Code
Synapse creates:
- Rust or JavaScript function
- Input query for cart data
- Discount calculation logic
- Output configuration
- Extension UI (optional)
3
Deploy & Test
- Automatic validation
- Deployed to dev store
- Test with different quantities
4
Activate Function
- Go to Discounts in admin
- Create new discount using your function
- Configure settings
- Set active dates
Generated Function Structure
Function Code Examples
- Rust (Recommended)
- JavaScript
- Input Query
Rust functions are faster and more efficient:
Common Discount Patterns
Buy X Get Y
Buy X Get Y
Buy one product, get another free/discounted:Prompt Example:
Spend Threshold
Spend Threshold
Discount when cart total reaches threshold:Prompt Example:
Customer Segment
Customer Segment
Discount for specific customer groups:Prompt Example:
Bundle Builder
Bundle Builder
Discount for buying complete sets:Prompt Example:
Function Configuration
Functions can have configurable settings:Testing Discount Functions
1
Create Discount in Admin
- Go to Discounts
- Create → Discount
- Select your function
- Configure settings
2
Test in Storefront
- Add eligible products to cart
- Verify discount appears
- Check discount amount is correct
- Test edge cases
3
Review Logs
Check function execution logs:View input/output for each execution
4
Performance Testing
- Test with many cart items
- Measure execution time
- Verify under 5ms threshold
Performance Best Practices
Discount functions must execute in under 5ms:Minimize Loops
Avoid nested loops over cart items
Use Rust
Rust functions are 10-100x faster than JavaScript
- Compiled to WebAssembly
- No garbage collection
- Type-safe
- Recommended for production
Cache Calculations
Don’t recalculate the same value
Limit API Surface
Only query data you need in run.graphql
Debugging Functions
- Local Testing
- Live Logs
- Error Handling
Test functions locally before deploying:
Limitations
Discount Functions have certain restrictions:| Limitation | Details |
|---|---|
| Execution Time | Must complete in under 5ms |
| No Network Calls | Cannot fetch external data |
| Deterministic | Same input must give same output |
| Stateless | No access to previous executions |
| Cart Data Only | Limited to provided input query |
Example Prompts
Tiered Spend Discount
Tiered Spend Discount
Mix and Match
Mix and Match
First Order Discount
First Order Discount
Loyalty Tier Pricing
Loyalty Tier Pricing