Skip to main content

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

  1. Go to Discounts in admin
  2. Create new discount using your function
  3. Configure settings
  4. Set active dates

Generated Function Structure

Function Code Examples

Common Discount Patterns

Buy one product, get another free/discounted:
Prompt Example:
Discount when cart total reaches threshold:
Prompt Example:
Discount for specific customer groups:
Prompt Example:
Discount for buying complete sets:
Prompt Example:

Function Configuration

Functions can have configurable settings:
Access settings in your function:

Testing Discount Functions

1

Create Discount in Admin

  1. Go to Discounts
  2. Create → Discount
  3. Select your function
  4. 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

Test functions locally before deploying:

Limitations

Discount Functions have certain restrictions:

Example Prompts

Next Steps

Payment Customization

Customize payment methods

Shipping Customization

Customize shipping rates

Functions Overview

Learn about all function types

Debugging

Debug and optimize functions