Skip to main content

What are Functions?

Shopify Functions are serverless functions that customize discounts, payments, shipping, and validation logic.

Function Types

Discounts

Volume discounts, BOGO, tiered pricing

Payment Customization

Hide/rename payment methods

Shipping Customization

Custom shipping rates and rules

Validation

Cart and checkout validation

Example: Volume Discount

export function run(input) {
  const quantity = input.cart.lines.reduce((total, line) => total + line.quantity, 0);
  
  if (quantity >= 10) {
    return {
      discounts: [{
        value: { percentage: { value: 20 } },
        targets: [{ productVariant: { id: "gid://..." } }]
      }]
    };
  }
  
  return { discounts: [] };
}

Key Features

  • JavaScript/Rust: Write in familiar languages
  • Fast Execution: Sub-100ms execution time
  • GraphQL Input: Query cart and customer data
  • Metafield Config: Configure via Shopify admin