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
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:Review Generated Code
Synapse creates:
- Rust or JavaScript function
- Input query for cart data
- Discount calculation logic
- Output configuration
- Extension UI (optional)
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
Test in Storefront
- Add eligible products to cart
- Verify discount appears
- Check discount amount is correct
- Test edge cases
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
Next Steps
Payment Customization
Customize payment methods
Shipping Customization
Customize shipping rates
Functions Overview
Learn about all function types
Debugging
Debug and optimize functions