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

Practical Shopify Script Examples for Functions

Table of Contents

  1. Introduction
  2. Understanding the Constraints: From Ruby to Functions
  3. Line Item Script Examples: Discounts and Pricing
  4. Shipping Script Examples: Delivery Customization
  5. Payment Script Examples: Controlling the Gateway
  6. Cart and Checkout Validation: The New Frontier
  7. Choosing the Right Approach: A Decision Framework
  8. The Nextools Playbook for Implementing Logic
  9. Advanced Customization with Checkout UI Extensions
  10. Why the Move to Functions Matters for Performance
  11. Nextools Shopify App Suite (Quick Links)
  12. Conclusion
  13. FAQ

Introduction

Managing a high-volume Shopify Plus store involves more than just a beautiful storefront; it requires a checkout experience that adapts to complex business logic. For years, merchants relied on Ruby-based Shopify Scripts to handle everything from tiered discounts to hiding specific shipping methods. However, the ecosystem is shifting. With the deprecation of Shopify Scripts scheduled for August 2025, merchants must transition to Shopify Functions and Checkout Extensibility. At Nextools, we specialize in making this transition seamless, helping Shopify Plus merchants, agencies, and developers replace legacy Ruby code with performant, future-proof logic.

The pressure to migrate is real. Whether you are dealing with shipping method conflicts, complex B2B discount stacks, or payment gateway fraud risks, the logic that once lived in the Script Editor must now be re-envisioned. This article provides a deep dive into practical shopify script examples—translated into the modern context of Shopify Functions—to help you maintain and improve your checkout performance.

Our goal is to help you navigate this transition using the Nextools Shopify App Suite. Whether you are an agency developer looking for a script migrator or a merchant needing a no-code solution for payment rules, understanding these examples is the first step toward a stable, scalable checkout.

To achieve a reliable setup, we follow a structured engineering workflow: we clarify your goals and constraints, confirm what the platform allows, choose the simplest durable approach, implement safely in a staging environment, and finally measure the impact on conversion and AOV.

Understanding the Constraints: From Ruby to Functions

Before diving into specific shopify script examples, it is essential to understand the structural differences between legacy Scripts and modern Shopify Functions. This technical context determines how you will implement your logic.

The Shopify Plus Requirement

Both legacy Scripts and modern Checkout Extensibility (including most Shopify Functions) are primarily features of the Shopify Plus plan. While some basic discount functions are available on all plans, the ability to customize delivery and payment logic—what used to be “Shipping Scripts” and “Payment Scripts”—is generally reserved for Plus merchants.

Execution Environments

Legacy Ruby Scripts ran on Shopify’s servers but were limited by execution time and memory. If a script was too “heavy,” it would time out, causing the checkout to revert to default behavior. Shopify Functions, however, are compiled into WebAssembly (Wasm). This allows them to run in under 10ms, ensuring that even the most complex logic doesn’t slow down the customer’s journey.

The Scope of Logic

In the old system, you had three main script types:

  1. Line Item Scripts: For discounts and pricing.
  2. Shipping Scripts: For renaming, reordering, or hiding shipping rates.
  3. Payment Scripts: For controlling the visibility of payment gateways.

In the modern era, these are replaced by specific Function APIs:

  • Product Discount API: Replaces Line Item Scripts.
  • Delivery Customization API: Replaces Shipping Scripts.
  • Payment Customization API: Replaces Payment Scripts.
  • Cart Transform API: Allows for more advanced bundle logic and price overrides.
  • Cart and Checkout Validation API: For preventing orders that don’t meet specific criteria.

At Nextools, we built SupaEasy specifically to bridge this gap. It serves as a Function generator and script migrator, allowing you to recreate legacy Ruby logic without needing to build and host a custom app from scratch.

Line Item Script Examples: Discounts and Pricing

Line item scripts were the most common use case for the Script Editor. They allowed for logic that the standard Shopify discount engine couldn’t handle, such as “Buy 3, Get 10% off” combined with specific customer tags.

Example 1: Tiered Bulk Discounts

A classic scenario involves offering discounts based on the quantity of a specific collection in the cart.

The Legacy Ruby Approach: The script would loop through all line items, check if the product belonged to a specific collection, and then apply a percentage discount if the quantity threshold was met.

The Modern Function Approach: Using the Product Discount API, you define a Function that triggers when the quantity of a specific category exceeds a limit.

  • Constraint: You must ensure the discount doesn’t conflict with other automatic discounts.
  • Implementation: You can use Multiscount to manage these tiered discounts. It allows for up to 12 product tiers on its Advanced plan ($15.99/month as listed on the Shopify App Store at time of writing), enabling you to stack or isolate these rules easily.

Example 2: BOGO (Buy One Get One) with Specific Exclusions

Standard BOGO rules often fail when you need to exclude items that are already on sale.

The Logic:

  1. Identify the “Trigger” item in the cart.
  2. Identify the “Target” item (often the cheapest item).
  3. Check the compare_at_price of the items. If an item is already discounted, exclude it from being the “Target” item.
  4. Apply a 100% discount to the Target item.

Implementation with Nextools: For Plus merchants migrating from Ruby, SupaEasy offers a “Scripts Migrator” and AI Functions Generator. This allows you to input your old Ruby logic and generate a Function that respects these complex exclusion rules.

Nextools Tip: When implementing BOGO logic via Functions, always test how the discount displays on the storefront versus the checkout. Functions provide a much cleaner “discount message” than legacy scripts, which often required theme hacks to show the “saved” amount correctly.

Shipping Script Examples: Delivery Customization

Shipping scripts allowed merchants to hide or rename shipping methods based on cart attributes, customer tags, or specific products. This is vital for stores selling heavy items, hazardous materials, or digital goods alongside physical ones.

Example 3: Hiding Express Shipping for Heavy Items

If a cart contains an item over 50kg, you might want to hide the “Overnight Express” option to prevent massive shipping losses.

The Logic:

  1. Sum the total weight of all items in the cart.
  2. Check the total weight against a threshold (e.g., 50,000 grams).
  3. If the weight exceeds the threshold, look for a shipping rate named “Express” and hide it.

Implementation with HideShip: Instead of writing a custom Function, HideShip allows you to do this via a user interface.

  • Workflow: In HideShip, you create a rule: “Hide shipping method” if “Cart weight” is “Greater than 50kg.”
  • Pricing: The Advanced plan ($5.99/month as listed on the Shopify App Store at time of writing) supports multiple conditions using AND/OR logic, which is perfect for complex shipping matrices.

Example 4: Renaming Rates Based on Delivery Date

Often, a merchant wants to change “Standard Shipping” to “Standard Shipping (Delivered by Friday)” based on the day of the week.

The Legacy Ruby Approach: Ruby scripts didn’t have native access to current time/date without significant workarounds, making this difficult to implement reliably.

The Modern Function Approach: The Delivery Customization API allows for dynamic renaming. Since Functions run at the moment of checkout, they can calculate the expected delivery window and append it to the rate name.

  • Nextools Strategy: Use SupaEasy to deploy a delivery customization function that checks the current timestamp and modifies the title property of the shipping rate.

Payment Script Examples: Controlling the Gateway

Payment scripts are critical for managing transaction fees and risk. For example, hiding “Cash on Delivery” (COD) for high-value orders or hiding PayPal for B2B customers who must pay via bank transfer.

Example 5: Hiding Specific Gateways for High-Risk Orders

If a customer has a specific tag or if the order value is exceptionally high, you may want to limit payment to secure methods like credit cards and hide “Buy Now, Pay Later” (BNPL) options to avoid high merchant fees.

The Logic:

  1. Identify the customer tag (e.g., “High-Risk” or “Wholesale”).
  2. Identify the cart total.
  3. If the condition is met, hide specific payment methods by name (e.g., “Klarna” or “Afterpay”).

Implementation with HidePay: HidePay is designed specifically for this use case.

  • Scenario: A merchant wants to hide PayPal for orders over $2,000 to avoid high percentage fees.
  • Rule Setup: In HidePay, select “Hide by cart total” and set the threshold. This logic is processed via Shopify Functions, ensuring it is secure and doesn’t interfere with the checkout UI.
  • Pricing: The Premium plan starts at $3.99/month (as listed on the Shopify App Store at time of writing), making it a cost-effective alternative to a custom-coded payment script.

Cart and Checkout Validation: The New Frontier

One of the most powerful additions to the Shopify Function ecosystem is the Validation API. While legacy scripts could modify prices or hide options, they couldn’t easily “block” a checkout with a custom error message.

Example 6: Blocking PO Box Addresses for Certain Products

Some shipping carriers cannot deliver specific items (like large furniture) to PO Boxes.

The Logic:

  1. Check the shipping address for keywords like “PO Box” or “Post Office Box.”
  2. Check the cart for “oversized” products.
  3. If both conditions are met, prevent the user from moving to the next step of the checkout and display a message: “We cannot ship oversized items to PO Boxes. Please provide a residential address.”

Implementation with Cart Block: Cart Block allows you to implement this without writing any code.

  • Safety: This is much safer than old theme-based hacks that tried to hide the “Checkout” button. Since this runs via the Validation API, it works even if a bot attempts to bypass the storefront UI.
  • Pricing: The Ultimate plan ($7.99/month as listed on the Shopify App Store at time of writing) is specifically for Shopify Plus merchants and allows blocking based on payment or delivery methods as well.

Choosing the Right Approach: A Decision Framework

When looking at shopify script examples, you must decide whether to use a dedicated app, a Function generator, or a custom build. At Nextools, we recommend the following decision tree:

  1. Is it a standard use case? (Hiding a payment method, simple shipping rules, tiered discounts).
    • Solution: Use a specialized app like HidePay, HideShip, or Multiscount. These are “durable” and easy to manage for non-developers.
  2. Is it a complex legacy script migration? (Complex Ruby logic with many exceptions).
    • Solution: Use SupaEasy. Its AI Functions Generator and Scripts Migrator are designed to translate your existing Ruby code into a modern Function without you having to build a custom App.
  3. Does it require custom UI elements in the checkout? (Adding a checkbox for insurance, a date picker, or a gift message).
    • Solution: Use SupaElements or Formify. These apps leverage Checkout Extensibility to inject UI components safely.
  4. Is it a highly unique, proprietary business logic?
    • Solution: This may require a custom-built Shopify Function. However, for most Plus merchants, the Nextools Shopify App Suite covers 95% of use cases with much lower maintenance overhead.

The Nextools Playbook for Implementing Logic

When moving from legacy scripts to modern Functions, we follow a rigorous process to ensure no disruption to your revenue.

1. Clarify the Goal and Constraints

Start by documenting exactly what the old script did. Does it only apply to certain Markets? Does it conflict with your existing discount stack? For example, if you use Shopify Markets to sell in both the US and EU, your shipping logic might need to be different for each. We ensure the solution accounts for these boundaries.

2. Confirm Platform Limits

Shopify Functions have limits. For instance, a Function cannot currently call an external API (like a third-party fraud score) in real-time. If your logic requires external data, you might need to use a combination of Metafields (populated beforehand) and Functions.

3. Choose the Simplest Durable Approach

We always advocate for the “simplest durable approach.” If you can achieve a result with HidePay rather than a custom-coded Function, the app is the better choice because it includes a managed UI and regular updates from our team.

4. Implement Safely

Never deploy logic directly to a live Plus store.

  • Staging: Use a development or sandbox store first.
  • QA Scenarios: Test with various cart combinations: empty carts, high-value carts, carts with mixed product types, and different customer tags.
  • Rollback Plan: With Shopify Functions, you can simply “deactivate” the function in the Shopify Admin if something goes wrong, providing an instant safety net.

5. Measure and Iterate

After implementation, monitor your checkout completion rates. Did hiding a specific payment method reduce your transaction fees without hurting conversion? Did the new discount logic increase your Average Order Value (AOV)? Use this data to refine your rules.

Advanced Customization with Checkout UI Extensions

While scripts focused on the “logic,” Checkout Extensibility allows you to customize the “look and feel” and collect more data. This often goes hand-in-hand with the logic described in our shopify script examples.

Collecting Custom Data

If your logic depends on a customer choice (e.g., “Is this a business order?”), you need a way to collect that data. AttributePro or Formify can add fields to the cart or checkout. That data is then saved as a Cart Attribute, which your Shopify Function can then read to apply a discount or hide a shipping method.

Boosting AOV with Auto-Add

Legacy scripts were often used to “auto-add” a free gift to the cart. This is now best handled by the Cart Transform API or specialized apps like AutoCart. AutoCart can automatically add companion products or gifts based on the items present, ensuring the customer sees the benefit immediately.

Why the Move to Functions Matters for Performance

Performance is a silent killer of conversion. Legacy Ruby Scripts were executed in a “sandbox” that could occasionally be slow, especially during peak traffic events like Black Friday Cyber Monday (BFCM).

Shopify Functions are significantly faster. Because they are pre-compiled, they execute almost instantly. This means the customer never sees a “loading” state when a discount is applied or a shipping rate is calculated. By migrating your shopify script examples to the Nextools Shopify App Suite, you are not just preparing for a deadline—you are optimizing your store for speed and reliability.

Nextools Shopify App Suite (Quick Links)

Explore our full range of tools designed to help you master Shopify Functions and Checkout Extensibility:

Conclusion

The transition from legacy Ruby Scripts to Shopify Functions is a significant milestone for the Shopify Plus ecosystem. While the August 2025 deadline might seem distant, the benefits of migrating early—improved performance, better merchant controls, and compatibility with the latest Checkout Extensibility features—are available today.

By following the Nextools Playbook, you can transform your complex logic into a series of manageable, high-performance rules:

  1. Clarify your goals and identify the specific script logic you need to replicate.
  2. Confirm the platform limits and determine which Shopify Function API is the right fit.
  3. Choose a durable approach, utilizing the Nextools Shopify App Suite to reduce custom code.
  4. Implement safely using development stores and comprehensive QA.
  5. Measure the outcomes to ensure your checkout remains a conversion-focused machine.

Don’t wait for the sunset of the Script Editor to begin your migration. Explore the Nextools App Suite hub today to find the tools that will power the next generation of your Shopify Plus checkout.

FAQ

Does every Shopify Script require a custom-built Function to replace it?

Not necessarily. Many common shopify script examples, such as hiding payment gateways or shipping methods, can be replaced with specialized apps like HidePay or HideShip. For more unique logic, tools like SupaEasy allow you to generate Functions via an AI wizard or a script migrator, often removing the need for a fully custom-built app.

Can I test my new Shopify Functions without affecting live customers?

Yes. Shopify Functions can be deployed to your store but remain “inactive” until you explicitly enable them in the Shopify Admin under Settings > Payments (for payment customizations) or Settings > Shipping and Delivery (for delivery customizations). We always recommend testing in a development or sandbox store first.

Are Shopify Functions only for Shopify Plus merchants?

While the most advanced customizations (like Delivery and Payment Customizations) are exclusive to Shopify Plus, basic Product Discount Functions are available on all Shopify plans. However, to fully replicate the power of legacy Scripts, a Plus plan is generally required to access the full range of Checkout Extensibility APIs.

How do I handle multiple scripts that need to run at the same time?

In the old system, you could only have one script of each type active at once, leading to “monolithic” scripts. With Shopify Functions, you can have multiple separate functions active simultaneously. However, you must be careful about how they interact—for example, ensuring that two different discount functions don’t stack in a way that hurts your margins. Apps like Multiscount help manage these relationships effectively.

SupaEasy is a product built & designed by Nextools

Company

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