A Script Editor alternative: write Shopify Functions in JavaScript

Updated · SMART Functions Creator (E-TRADE PARTNER)

Shopify's Script Editor ran Ruby scripts and stopped on 2026-06-30. SMART Functions Creator has a script editor where you write a function's logic in JavaScript instead, for payment and delivery customizations, cart and checkout validations, product, order and shipping discounts, and cart transforms. It does not run or convert Ruby: you rewrite each script, usually starting from one of 32 templates, and test it on a sample cart before it goes live.

SMART Functions Creator builds this as a Shopify Function, with rules or in JavaScript.

Start free trial
On this page
  1. Rule builder or script editor
  2. Create a script function
  3. What your code receives and returns
  4. Templates by function type
  5. Discounts have two code tabs
  6. Test before it goes live
  7. When code fails at checkout
  8. Limits to know before you start
  9. Version history for scripts
  10. Plans
  11. Frequently asked questions

Rule builder or script editor

The app has two ways to build a function. The rule builder covers most Scripts logic with conditions, Line groups and actions, and needs no code. The script editor is for logic the builder can't express, or for teams that wrote Ruby and would rather keep working in code. Both create the same five Function types and run in Shopify's checkout.

Examples where a script does what the builder can't, each with a ready template in the editor:

  • A discount percentage stored on each product in a metafield. The builder reads metafields only as conditions; the template "Discount set per product in a metafield" reads the value as the percentage.
  • Quantity limits for every product at once. The builder needs one Line group per product; "Quantity limits per product" checks each product in the cart by itself.
  • Case packs: each product in multiples of its case size, with a minimum order, for B2B buyers or everyone ("Case packs and B2B minimum order").
  • Only the cheapest shipping rates, when your carriers return too many ("Show only the cheapest rates").
  • A discount set by a line item property your theme or another app adds, such as a supply length ("Discount set by a line item property").

Create a script function

  1. In the app, choose Create new function, pick the function type, then Script editor.
  2. Pick the Function input: Standard or Advanced. It decides what data your code receives and is locked once the function is created.
  3. Keep the example code or open Templates. Templates put their settings at the top, with plain comments, and amounts typed in your store currency.
  4. Fill in the values your code checks, such as customer tags, product tags, collections, a line item property key or a metafield namespace and key. The input card shows how the code reads each one.
  5. Click Test to run the code on a sample cart, then save. Payment, delivery and validation functions are saved inactive; a discount follows its Active dates.
  6. Activate the function and check out with a real cart on your store.

What your code receives and returns

Your code is the body of a function that receives input and returns { operations: [...] } in Shopify's output format for that function type, such as paymentMethodHide, deliveryOptionRename or validationAdd. Returning an empty list changes nothing at checkout.

Function inputWhat the code can read
StandardCart totals, the customer, products with their tags and collections, and the shipping address
AdvancedLine item properties, a cart attribute, selling plans, a product metafield and the B2B company. Discounts can also read a variant metafield
Cart transform (Standard only)Cart lines with prices and two line item properties, products with their tags and a metafield, and the customer's tags

This is the "Hide Cash on Delivery for big orders" template for a payment customization, unchanged. It does a job many payment scripts did:

// Hide Cash on Delivery for big orders, some products or other countries.
// Amounts are in your store currency.
const METHOD_NAME = "Cash on Delivery"; // part of the payment method's name
const MAX_ORDER_TOTAL = 300; // hide above this order total, 0 = no limit
const MAX_ITEMS = 0; // hide above this many items, 0 = no limit
const PRODUCT_TAG = "no-cod"; // hide when a product has this tag (add it under Product tags)
const COUNTRIES = []; // only offer it in these countries, e.g. ["US", "CA"]; empty = all

const rate = parseFloat(input.presentmentCurrencyRate || 1);
const cart = input.cart;
const total = parseFloat(cart.cost.totalAmount.amount);
const items = cart.lines.reduce((sum, line) => sum + line.quantity, 0);
const country = cart.deliveryGroups[0]?.deliveryAddress?.countryCode;
const tagged = cart.lines.some((line) =>
  line.merchandise.__typename === "ProductVariant" &&
  line.merchandise.product.hasTags.some((t) => t.tag === PRODUCT_TAG && t.hasTag));

const hide =
  (MAX_ORDER_TOTAL > 0 && total > MAX_ORDER_TOTAL * rate) ||
  (MAX_ITEMS > 0 && items > MAX_ITEMS) ||
  tagged ||
  (COUNTRIES.length > 0 && !!country && !COUNTRIES.includes(country));
if (!hide) return { operations: [] };

const name = METHOD_NAME.toLowerCase();
return {
  operations: input.paymentMethods
    .filter((method) => method.name.toLowerCase().includes(name))
    .map((method) => ({ paymentMethodHide: { paymentMethodId: method.id } })),
};

Templates by function type

Function typeTemplatesExamples
Discount8Quantity breaks, spend more save more, VIP and first-order discount, free shipping over an amount, discount per bundle ID
Payment customization5Hide Cash on Delivery for big orders, pay in store only for local pickup, reorder payment methods
Delivery customization6Hide rates by postcode or region, hide paid rates when shipping is free, rename and reorder rates
Cart and checkout validation8Minimum or maximum order amount, block PO boxes and check the address, products that must be ordered separately
Cart transform5Merge items into a bundle by property, expand a bundle into its components, mix and match bundle at a fixed price

Discounts have two code tabs

Shopify runs product and order discounts separately from shipping discounts, so a discount script has a Product and order discounts tab and a Shipping discounts tab. Leave one empty if the discount doesn't need it. Active dates, combinations, usage limits, purchase types and eligibility are set in the same cards as in the rule builder.

Test before it goes live

  • Test runs your code in your browser on a sample cart, without saving. The sample is editable JSON, so you can change quantities, tags or the address and run it again. It also shows you the exact data your code can read.
  • The result shows what the code returned, any error, and anything it logged with console.log. A run that takes longer than 2 seconds is stopped.
  • The test checks that each operation is one Shopify accepts for that function type. Shopify checks every field at checkout, so the final check is a real checkout on your store.

When code fails at checkout

  • If the code throws an error or doesn't return { operations: [...] }, a discount, payment or delivery script changes nothing and checkout continues.
  • A validation or cart transform script fails the run instead, and the function's Block checkout on failure setting decides whether checkout stops. It is off by default. The errors your validation returns on purpose always block checkout.

Limits to know before you start

  • No Ruby. Scripts used Shopify's Ruby API, and nothing converts it. Each script has to be rewritten in JavaScript, or rebuilt as rules.
  • 10KB per function. Your code and the values it checks must fit Shopify's 10KB limit for a function's settings. The Function size meter shows the usage; comments and spaces count. Saving is refused over the limit.
  • Only the input's data. The code reads what its Function input provides and can't call other services. The inputs don't include the store's local time, the billing address, entered discount codes or customer metafields.
  • No discount-code rejection. Neither the script editor nor the rule builder rejects an entered code with a message.
  • Shopify's execution limits apply. Shopify stops a function that does too much work on a cart. Keep loops small and test large carts. See limits and budgets.
  • Plus-only operations stay Plus-only. Payment terms, order review and cart transform line updates need Shopify Plus; the templates that use them say so.
  • AI connections can read script functions but not edit them or turn them on or off. Export JSON and Import JSON are for rule-builder functions.

Version history for scripts

Every save keeps a version, up to 50 per function (the first and the newest 49; identical saves are skipped). The versions table sits under the code. Open a version to see it side by side with the code in the editor, then Restore to load it as unsaved changes and save to keep it.

Plans

The script editor is included on both plans: Lite at $19.99/month for up to 2 active functions and Pro at $39.99/month for unlimited active functions, after a 7-day free trial. A script function counts like any other function. See pricing.

Write your first script on a free trial

32 templates, a test run on a sample cart, and version history, on Lite and Pro.

Start free trial

Frequently asked questions

›Can I paste my old Ruby script into the script editor?

No. The script editor runs JavaScript, and Shopify's Ruby Scripts API does not exist in Functions. Rewrite the logic, starting from the closest template, or rebuild it as rules in the builder.

›Do I need Shopify Plus for the script editor?

No. It works on Basic, Grow, Advanced and Plus stores. Operations that Shopify keeps for Plus, such as payment terms and cart transform line updates, still need Plus.

›Is the script editor on the Lite plan?

Yes. Lite and Pro have the same features, including the script editor. Lite allows up to 2 active functions; Pro has no app limit.

›Can someone write the script for me?

Yes. Describe the rule in the app chat or by email and support can write the script with you or check yours.

Related articles