⚠️   Shopify Scripts will no longer be supported as of June 30, 2026  ⚠️   read the Shopify article 

Mastering Custom Discount Shopify Logic with Functions

Table of Contents

  1. Introduction
  2. The Evolution of Custom Discounts: From Scripts to Functions
  3. Clarifying the Goal and Constraints
  4. Confirming Platform Capabilities and Limits
  5. Choosing the Simplest Durable Approach
  6. Implementing Safely: The Nextools Workflow
  7. Custom Discount Scenarios for Shopify Plus
  8. Measuring Impact and Iterating
  9. Choosing the Right Nextools Tool: A Decision Checklist
  10. The Technical Deep-Dive: Building with the Shopify CLI
  11. Compliance and Trust in Discounting
  12. Nextools Shopify App Suite (Quick Links)
  13. Conclusion
  14. FAQ

Introduction

Modern Shopify merchants, particularly those on Shopify Plus, are currently navigating a significant architectural shift. The sunsetting of Shopify Scripts—the Ruby-based logic that once powered complex checkouts—has created a technical void that must be filled by Shopify Functions. This transition is not merely a “like-for-like” replacement; it represents a fundamental change in how a custom discount Shopify strategy is executed. For high-volume brands, the stakes are high: legacy scripts must be migrated before deadlines, or critical business logic like tiered pricing, B2B-specific discounts, and complex gift-with-purchase (GWP) workflows will cease to function.

At Nextools, we specialize in bridging this gap between sophisticated business requirements and the technical constraints of the new Shopify checkout. Whether you are a Shopify Plus merchant looking to retain competitive discounting logic, an agency developer tasked with a complex migration, or a merchant-owner seeking to scale, understanding the mechanics of Shopify Functions is essential. We focus on building future-proof tools that eliminate the overhead of maintaining custom app infrastructure while providing the depth needed for advanced logic.

This post will guide you through the transition from Scripts to Functions, the technical architecture of custom discounts, and the strategic workflow we use at Nextools to ensure reliable outcomes. Our approach follows a structured, engineering-minded playbook: we clarify your goals and constraints, confirm the platform’s current capabilities, choose the most durable implementation path—often leveraging our Nextools Shopify App Suite—implement safely in staging, and measure the impact on your conversion and average order value (AOV).

The Evolution of Custom Discounts: From Scripts to Functions

For years, Shopify Scripts were the gold standard for creating a custom discount Shopify experience. They allowed for server-side logic that could modify prices, hide payment methods, and customize shipping rates in real-time. However, Scripts were limited by their execution environment and lack of visibility in the Shopify Admin.

Shopify Functions have changed the landscape. Functions allow developers to write custom logic in languages like Rust or JavaScript, which is then compiled to WebAssembly (Wasm) and executed on Shopify’s global infrastructure. This shift offers several advantages:

  • Performance: Functions execute in under 10ms, ensuring that even the most complex discount logic does not slow down the checkout experience.
  • Visibility: Unlike Scripts, which were often “invisible” until the checkout page, Functions can be integrated directly into the Shopify Admin, allowing merchants to configure rules through familiar interfaces.
  • Reliability: Because Functions run on Shopify’s infrastructure, they are not subject to the same “noisy neighbor” issues or execution timeouts that could occasionally plague complex Ruby scripts.

However, for many merchants, the move to Functions presents a hurdle. It requires development knowledge, CLI familiarity, and a hosted app structure. This is where the Nextools Shopify App Suite simplifies the process, providing pre-built Function templates and AI-assisted generation through apps like SupaEasy.

Clarifying the Goal and Constraints

Before writing a single line of code or installing an app, we must define the parameters of the discounting strategy. A custom discount Shopify implementation is only as good as the requirements gathering that precedes it.

Shopify Plan Requirements

The first constraint is the Shopify plan. While basic automatic discounts and discount codes are available to all merchants, the ability to deploy custom Shopify Functions generally requires a Shopify Plus plan or a development store for testing. It is important to note that while some third-party apps can provide advanced discounting logic for non-Plus stores, the most deeply integrated “custom” logic—those that interact directly with the checkout engine via Wasm—is a Plus-exclusive territory.

Discount Classes and Stacking

One of the most common points of confusion in custom discounting is how different “classes” of discounts interact. Shopify categorizes discounts into three main classes:

  1. Product Discounts: Applied to specific line items.
  2. Order Discounts: Applied to the total subtotal.
  3. Shipping Discounts: Applied to the delivery rates.

The “Combination” logic in Shopify determines if these can be stacked. When building a custom discount, you must decide if your Function should allow its output to be combined with other active discounts. This is a critical decision in preventing “discount stacking” where a merchant might unintentionally lose margin by allowing a 20% product discount to stack with a $50 order-level discount.

Market and B2B Context

With the rise of Shopify Markets and B2B on Shopify, custom discounts must now be context-aware. Does the discount apply only to your US market? Is it restricted to B2B customers with a specific company tag? Shopify Functions are uniquely suited for this because the “Input Query” can pull in customer tags, market IDs, and purchasing company data to determine eligibility.

Confirming Platform Capabilities and Limits

The power of a custom discount Shopify Function lies in its Input Query and Output Operations. At Nextools, we advise developers and merchants to familiarize themselves with what a Function can and cannot see.

The Input Query

The Input Query is a GraphQL-based request that defines the data the Function needs from the cart. This can include:

  • Cart lines (product IDs, variants, quantities, prices).
  • Customer details (tags, total spent, order count).
  • Delivery groups (for shipping-specific discounts).
  • Custom attributes (cart attributes or line-item properties).

The Output Operations

The Function does not “change” the price directly; instead, it returns an “Operation.” This operation tells Shopify: “Apply a 10% discount to this specific line item” or “Apply a fixed amount of $10 off the order subtotal.”

Current Platform Limits

It is vital to recognize the current limits of Checkout Extensibility and Functions:

  • Payload Size: The Input Query and the resulting Output must stay within specific byte limits.
  • Execution Time: Functions must complete within the 10ms window.
  • External Calls: Functions cannot make external API calls (e.g., to a third-party CRM or a private database) during execution. All data needed for the decision must be present in the Input Query or stored within the Function’s configuration (metafields).

Choosing the Simplest Durable Approach

At Nextools, we believe in the principle of “least complexity.” If a native Shopify feature can achieve the result, use it. If not, use a specialized tool that minimizes custom code maintenance.

When to Use SupaEasy

For merchants migrating from Shopify Scripts or those needing complex logic without maintaining a custom server, we recommend SupaEasy. It acts as a Shopify Functions generator.

  • Scenario: You need a “Buy 3, Get 1 Free” discount that only applies to items in a specific collection, but only for customers who have spent over $500 in the last year.
  • Solution: SupaEasy’s AI-assisted Function creator or its template library allows you to deploy this logic without writing Rust code. It handles the deployment and hosting of the Function on your behalf.

When to Use Multiscount

For high-volume stores where the goal is maximizing AOV through “Volume Discounts” or “Tiered Offers,” Multiscount is the preferred choice.

  • Scenario: A merchant wants to show a “Buy More, Save More” widget on the product page and have those discounts stack automatically and reliably at checkout.
  • Solution: Multiscount provides the storefront widgets and the backend Function logic to handle tiered product pricing and order-level gift tiers (GWP) seamlessly.

When to Use AutoCart

If the custom discount is actually a “Free Gift” strategy, AutoCart is the right tool.

  • Scenario: Adding a specific “Free Sample” variant to the cart automatically when the total exceeds $100.
  • Solution: AutoCart handles the automated addition/removal of items and works in tandem with Discount Functions to ensure the gift price is set to zero.

Implementing Safely: The Nextools Workflow

Implementation is where most errors occur. We follow a strict QA process to ensure that a new custom discount Shopify rule doesn’t break the checkout for thousands of customers.

Phase 1: Development and Sandbox Testing

Never deploy a new Function directly to a live store. Use a Shopify Plus sandbox or a development store. This allows you to test the Input Query using tools like GraphiQL. You can simulate different cart scenarios—different countries, customer tags, and product combinations—to see exactly what operations the Function returns.

Phase 2: Configuration via Metafields

Modern Functions are “data-driven.” This means the logic is written once, but the specific values (e.g., which collection gets the discount) are stored in Shopify Metafields. This allows a merchant to change the discount percentage from the Shopify Admin without needing a developer to update the code. When using the Nextools Shopify App Suite, this configuration is handled through our intuitive app interfaces.

Phase 3: The “Dry Run”

Before making a discount “Automatic,” we often recommend testing it as a “Discount Code” first. This allows for controlled testing by staff members or a small segment of loyal customers. Once the logic is verified to be accurate across all edge cases (such as returns, partial captures, and multi-currency orders), it can be converted to an automatic discount.

Custom Discount Scenarios for Shopify Plus

To illustrate the depth of custom discount Shopify logic, let’s look at three practical, real-world scenarios handled by the Nextools ecosystem.

Scenario A: Complex B2B Tiered Pricing

A wholesale merchant needs to offer different discounts based on the customer’s “Membership Tier.”

  • Tier 1 (Tag: Gold): 20% off all products.
  • Tier 2 (Tag: Silver): 10% off all products.
  • Exception: Discounts do not apply to products already on sale (Compare-at price > Current price).
  • Implementation: Using SupaEasy, a Function is created that parses the customer.tags and the line_item.variant.compare_at_price. The Function filters the cart lines and applies the appropriate percentage only to eligible items.

Scenario B: Market-Specific Shipping Discounts

A global brand wants to offer free shipping to EU customers, but only if they don’t have a “Heavy Item” in their cart, and only if the order total is above €150.

  • The Constraint: This logic must identify the Shopify Market (EU) and check product tags for “Heavy.”
  • The Tool: HideShip or ShipKit. While these apps handle the visibility and creation of rates, they utilize the Discount API to “zero out” shipping costs when conditions are met. This ensures the customer sees “Free Shipping” clearly at checkout.

Scenario C: Preventing Fraud and Discount Abuse

A merchant running a high-profile “Hype Drop” wants to prevent customers from using a specific discount code if they are using a suspicious email domain or if they have more than 5 items in their cart (to prevent resellers).

  • The Tool: Cart Block. While primarily a validation tool, Cart Block can “block” the checkout or prevent certain discounts from being applied if specific criteria are met. This is a crucial part of a “Custom Discount” strategy—knowing when not to give a discount.

Measuring Impact and Iterating

A successful custom discount Shopify strategy is not “set and forget.” You must measure how these rules impact your bottom line.

  • Conversion Rate: Did the new tiered discount structure increase the number of completed checkouts, or did it add too much complexity?
  • Average Order Value (AOV): By using tools like Multiscount, are customers actually adding more to their cart to hit the next discount tier?
  • Margin Health: Use Shopify’s built-in reports to ensure that the total discount amount across all orders isn’t exceeding your marketing budget.

At Nextools, we encourage merchants to iterate. If a 15% discount isn’t moving the needle, perhaps a “Buy X, Get Y” offer via AutoCart will perform better. The beauty of Shopify Functions and the Nextools Shopify App Suite is the agility they provide; you can pivot your strategy in minutes, not weeks.

Choosing the Right Nextools Tool: A Decision Checklist

When deciding which app in our suite to use for your custom discount Shopify needs, consider the following checklist:

  1. Do you need to migrate a complex Shopify Script?
    • Use SupaEasy. It is specifically designed for Script-to-Function migration and offers AI generation for logic that once required Ruby.
  2. Is your goal to offer volume-based pricing or simple tiers?
    • Use Multiscount. It is optimized for “Buy More, Save More” scenarios and includes the necessary storefront widgets.
  3. Are you trying to automate gifts or “companion” products?
    • Use AutoCart. It handles the logic of adding items to the cart and works with Functions to adjust their prices.
  4. Do you need to hide or rename payment/shipping methods based on discounts?
    • Use HidePay or HideShip. These tools ensure that your checkout remains clean and logic-driven, preventing customers from using unauthorized payment methods on discounted orders.
  5. Do you need to translate your checkout for global discounts?
    • Use CartLingo. It ensures that your custom discount descriptions and checkout fields are localized for every market.

The Technical Deep-Dive: Building with the Shopify CLI

For the developers reading this, creating a custom discount Shopify Function often starts with the Shopify CLI. Here is a high-level overview of the engineering workflow:

1. Generating the Extension

Using the command shopify app generate extension, you select the Discount - Cart Transformer or Discount - Product/Order template. We generally recommend Rust for high-performance logic, though JavaScript is increasingly viable for simpler rules.

2. Defining the shopify.extension.toml

This file is the manifest of your Function. It defines the “Target”—where the logic runs. For discounts, this is typically cart.lines.discounts.generate.run.

3. Writing the Input Query

Your run.graphql file must be precise. Avoid over-fetching data. If you only need customer tags and product quantities, don’t fetch the entire product description. This keeps the Function payload small and fast.

4. Logic Implementation

In the run.rs (Rust) or run.js (JavaScript) file, you implement your business logic.

  • Filter: Identify which lines are eligible.
  • Calculate: Determine the discount amount.
  • Return: Construct the DiscountResponse object.

5. Deployment and Linking

Once the Function is deployed, it must be “linked” to a discount object in the Shopify Admin. This is done via a GraphQL mutation: discountAutomaticAppCreate. This step creates the “Active” discount that customers will actually trigger in the cart.

If this process sounds daunting, this is precisely why SupaEasy exists. It abstracts the CLI, the GraphQL mutations, and the hosting, allowing you to focus on the logic itself.

Compliance and Trust in Discounting

When implementing custom discounts, it is vital to remain compliant with consumer protection laws. In many jurisdictions (such as the EU under the Omnibus Directive), merchants are required to show the “lowest price in the last 30 days” alongside any discount. While Shopify Functions handle the price adjustment, ensuring your storefront branding and messaging remain compliant is your responsibility.

Additionally, data privacy is paramount. When building custom logic that utilizes customer data, ensure you are only fetching the minimum required information. At Nextools, our apps are built with privacy-by-design, ensuring that we never store sensitive customer data longer than necessary to execute the requested logic.

Nextools Shopify App Suite (Quick Links)

Explore our full range of tools designed to optimize your Shopify checkout and custom discount logic:

Conclusion

Building a robust custom discount Shopify strategy is no longer a matter of writing a quick Ruby script. It requires an engineering mindset that respects the boundaries of Shopify Functions and the performance requirements of a modern checkout. By following the Nextools Playbook—clarifying constraints, choosing the simplest durable approach, and implementing safely—you can create discounting experiences that drive real growth without compromising store stability.

As you look to migrate from legacy Scripts or scale your existing Plus store, remember that the goal is not just to “offer a discount,” but to create a logic-driven checkout that serves your specific business goals. We invite you to explore the Nextools Shopify App Suite to find the specialized tools that will make this transition seamless and profitable.

Actionable Summary Checklist:

  1. Inventory existing logic: Identify which Shopify Scripts must be migrated before the 2024/2025 deadlines.
  2. Define your constraints: Confirm if you are on Shopify Plus and identify the Markets and customer segments involved.
  3. Choose your tool: Determine if you need the AI-assisted power of SupaEasy or the specific tiered logic of Multiscount.
  4. Test in sandbox: Never push code or new app logic directly to production.
  5. Monitor and iterate: Use analytics to ensure your discounts are positively impacting AOV and conversion rates.

FAQ

Does custom discount Shopify logic always require a Shopify Plus plan?

While basic automatic discounts and codes are available to all, creating truly custom logic using Shopify Functions generally requires a Shopify Plus plan. This is because Functions are deployed as part of an app, and the advanced Checkout Extensibility features they interact with are limited to Plus merchants. However, developers can build and test these in Free Development Stores or Plus Sandbox stores at no cost.

How do I handle conflicts between multiple custom discounts?

Shopify uses “Discount Classes” (Product, Order, Shipping) and “Combination” settings to manage interactions. In your Function logic, you can specify if a discount can be combined with others. If conflicts arise (e.g., two different Product Functions targeting the same item), Shopify typically applies the one that offers the best value to the customer, but careful planning in your Nextools Shopify App Suite settings can help you define the exact priority.

Can I migrate my old Ruby Scripts to Shopify Functions automatically?

There is no “one-click” converter because Ruby (Scripts) and Rust/Wasm (Functions) are fundamentally different. However, tools like SupaEasy include a “Scripts Migrator” and AI assistance that can interpret your old Ruby logic and help you recreate it within the Functions framework, significantly reducing the manual development time.

How should I test a new custom discount Function before going live?

The gold standard is to use a Shopify development store and the Shopify CLI. You can use the app function replay command to simulate cart payloads and see exactly how your logic responds. Once verified locally, deploy to a staging environment and test the end-to-end checkout flow with real products and test payment methods (like Shopify’s “Bogus Gateway”) before enabling it for the public.

SupaEasy is a product built & designed by Nextools

Company

© [2024] website by Nextools. All Rights Reserved. PIVA: 16711981007