What Are Shopify Functions?
Shopify Functions let you write backend logic directly in the Shopify Admin without spinning up a separate app server. You write JavaScript or TypeScript, push it to Shopify, and it executes serverless—instantly, at checkout time, on every order.
Before Functions, customizing discount rules or payment logic required either (a) a third-party app with monthly fees, or (b) a custom API server that you owned and operated. Both were overkill for simple business logic.
Functions changed that math. Now you can implement conditional discounts, custom delivery logic, and payment gating directly in Shopify's runtime. Shopify manages the infrastructure. No servers to manage. No app marketplace dependency.
Think of Functions as Shopify's answer to AWS Lambda: write code, define a trigger, deploy. When that trigger fires (order placed, checkout started, discount evaluated), your function executes and returns a result.
The 4 Function Types (And When to Use Each)
Shopify Functions currently supports four use cases:
1. Discounts (Conditional Discounts)
What it does: Create discounts based on custom logic without listing them in your Shopify discount admin.
Example: "If cart total is over $500 AND customer has purchased before, apply 15% off. But if cart contains our clearance collection, cap the discount at 5%."
Before Functions, you'd need a third-party app (Recharge, Bold, Loop) to implement conditional logic. Now you write a function:
export default function run(input) {
const cartTotal = input.cart.cost.subtotalAmount.amount;
const isRepeat = input.customer && input.customer.orders > 0;
if (cartTotal > 500 && isRepeat) {
return {
discounts: [{
message: "Loyalty Discount",
targets: {
lineItem: [{ id: "gid://shopify/LineItem/1" }]
},
value: {
percentage: {
value: "15.0"
}
}
}]
};
}
return { discounts: [] };
}
Deploy this, and Shopify runs it on every checkout. No external app, no API calls, no latency.
Cost trade-off: Free. (Shopify Functions discounts have no app fee. Other function types charge per invocation after a free tier.)
2. Cart Transforms (Modify Cart Before Checkout)
What it does: Add, remove, or modify line items in the cart automatically.
Example: "If cart contains Product X, add the complementary Product Y at 30% off."
export default function run(input) {
const hasProductX = input.cart.lines.some(
line => line.merchandise.product.id === "gid://shopify/Product/123"
);
if (hasProductX) {
return {
operations: [
{
type: "addCartLine",
merchandiseId: "gid://shopify/ProductVariant/456",
quantity: 1
}
]
};
}
return { operations: [] };
}
Cost trade-off: $0.01–$0.05 per invocation (free tier: 10K invocations/month). Most stores stay under the free tier.
3. Delivery Customization (Shipping Logic)
What it does: Enable or disable shipping methods, modify shipping costs, or show different shipping options based on cart contents.
Example: "Hide express shipping if cart contains fragile items. Show local pickup only if customer is within 50 miles."
This replaces third-party shipping apps (ShipStation, Shippo) for basic use cases.
Cost trade-off: $0.01–$0.05 per invocation.
4. Payment Customization (Payment Methods)
What it does: Enable or disable payment methods based on customer, location, or cart contents.
Example: "If customer is from Taiwan, show Taiwan Pay. If cart total exceeds $5,000, hide Shopify Payments and require ACH transfer only."
This eliminates the need for payment-gating apps.
Cost trade-off: $0.01–$0.05 per invocation.
Why Functions Beat Apps: The Economics
| Feature | Third-Party App | Shopify Function |
|---|---|---|
| Setup Time | 30–60 min | 5–10 min (if you know code) |
| Monthly Cost | $50–$500 | Free–$500/month (pay-per-use) |
| Latency | 500–2000ms | <100ms (native) |
| Scalability | Depends on vendor | Unlimited (Shopify handles it) |
| Customization Depth | Limited to app features | Anything you can code |
| Vendor Lock-in | Yes (hard to uninstall) | No (easy to redeploy) |
The hidden cost of apps: They slow down checkout. Every third-party app integration adds API round-trip latency. Functions execute inside Shopify's checkout process, so zero external latency.
Practical example: A Shopify Plus store running Recharge (subscriptions), Bold (discounts), and Shippo (shipping) sees ~800ms added checkout latency from app integrations. A Functions-based discount system adds <10ms.
How to Deploy a Function (Non-Developers, This Requires a Developer)
Functions require Node.js and the Shopify CLI. If you don't code, hire someone—but it's cheap. A mid-level Shopify developer can build + deploy a custom discount function in 4 hours.
High-level workflow:
-
Create a function directory using Shopify CLI
shopify app function create --template discount -
Write your logic in
run.js -
Test locally using the Shopify sandbox
-
Deploy to Shopify (one CLI command)
-
Create the discount in Shopify Admin (assign the function)
-
Test in staging before going live
Total deployment time: ~10 minutes once code is written.
Real-World Function Examples for Shopify Stores
Example 1: Loyalty Discount Based on Purchase History
Offer 10% off to repeat customers automatically.
export default function run(input) {
const customer = input.cart.buyerIdentity.customer;
if (customer && customer.numberOfOrders > 2) {
return {
discounts: [{
message: "Repeat Customer Discount",
targets: { allLineItems: {} },
value: { percentage: { value: "10.0" } }
}]
};
}
return { discounts: [] };
}
Example 2: Free Shipping on Orders Over $100
Trigger a free shipping offer when cart total exceeds threshold.
Example 3: Bundle Discount (Buy 2, Get 3rd at 50% Off)
Identify if cart contains 3+ items from a collection, apply discount to lowest-price item.
Example 4: Wholesale-Only Payment Methods
If customer tag is "wholesale," show only ACH and bank transfer; hide consumer credit cards.
Common Pitfalls and How to Avoid Them
Pitfall 1: Over-Complicating the Logic
Functions should be simple. If your logic requires external API calls (to a third-party service), Functions become slower than apps. Keep logic inside the cart/customer/product data.
Pitfall 2: Forgetting to Handle Edge Cases
What if the customer is not logged in? What if the cart is empty? What if the product doesn't have a matching variant? Write defensively:
const customer = input.cart.buyerIdentity.customer;
if (!customer) {
// Guest checkout logic
return { discounts: [] };
}
Pitfall 3: Not Testing on Live Orders
Always test discount functions with real checkout orders before deploying widely. Bugs here directly affect revenue.
FAQ
Q: Can I use Functions for everything (replace all apps)?
A: No. Functions are for backend logic. They can't handle UI changes, email sequences, or inventory syncing. Use apps for those. But for checkout rules, discounts, and payment filtering, Functions win.
Q: What if I'm not technical? Can someone else write my function?
A: Yes. Hire a Shopify developer (Shopify Experts marketplace has vetted freelancers). Budget $1,500–$3,000 for a custom function. Still cheaper than a $500/month app for a year.
Q: Do Functions work on Shopify Basic, or only Plus?
A: Functions work on all Shopify plans, but discount Functions are free. Payment and delivery Functions require Shopify Plus or a third-party app integration.
Q: Can I modify Functions after deployment?
A: Yes. Edit your code, redeploy (takes seconds), and it's live. No approval process.
Q: What if my function has a bug and breaks checkout?
A: Shopify disables broken functions automatically (if they cause errors on >1% of orders). You'll get an alert in the Admin.
Ready to Eliminate Checkout App Bloat?
If you're paying for multiple checkout-related apps (discount, shipping, payment gating), Functions could consolidate and simplify. You'll reduce latency, cut costs, and own your logic outright.
Tenten helps Shopify merchants architect serverless functions and migrate off app dependencies. Let's audit your checkout stack and identify which functions could replace your current apps.
Contact us at tenten.co/contact
Editorial Note
Shopify Functions offer a simpler, faster, and cheaper way to customize checkout logic without third-party apps. They're best for discount rules, payment gating, and delivery customization. For UI changes or complex integrations, apps remain necessary.