Shopify Functions examples
Small, tested Functions for the checkout rules stores ask for most. Each one has the input query, the code, the extension config and test fixtures you can run.
In short
These are free Shopify Functions written in JavaScript for API version 2026-10. Each page covers one rule, such as hiding Cash on Delivery above a cart total or blocking PO box addresses, with the input query, the run function, the shopify.extension.toml and test input and output you can run with the Shopify CLI. Shopify Scripts stopped running on 30 June 2026; these are the Function equivalents.
- 22 pages, free to use in any store, including client work (MIT license)
Payment customization
Hide, rename or reorder payment methods at checkout, and set payment terms for B2B.
Hide Cash on Delivery above a cart total
A Shopify payment customization Function that hides Cash on Delivery when the cart total is above a limit you set, with tested JavaScript.
Hide Cash on Delivery by country, province or ZIP code
A Shopify payment customization Function that hides Cash on Delivery for countries, provinces or ZIP prefixes you list in a metafield. Tested JavaScript.
Rename and reorder payment methods at checkout
A Shopify payment customization Function that renames payment methods and changes their order at checkout from a JSON metafield. Tested JavaScript.
Net payment terms for B2B buyers
A Shopify payment customization Function that sets Net 30 (or 7–90 day) payment terms and an optional deposit for B2B company buyers. Shopify Plus.
Delivery customization
Hide, rename or reorder the shipping options a customer sees.
Hide express shipping for heavy carts
A Shopify delivery customization Function that hides express rates when a shipment weighs more than a limit, 30 kg by default. Tested JavaScript.
Hide shipping rates by product tag
A Shopify delivery customization Function that hides chosen shipping options when the cart has a product with a given tag, such as oversized or hazmat.
Add a delivery note to shipping option names
A Shopify delivery customization Function that appends a delivery note such as “3–5 business days” to shipping option names, by title and country.
Hide courier delivery options for PO box addresses
A Shopify delivery customization Function that hides UPS, FedEx and other courier options when the shipping address is a PO box. Tested JavaScript.
Cart and checkout validation
Stop a checkout with a clear message when the cart or address breaks a rule.
Block PO box shipping addresses
A Shopify cart and checkout validation Function that stops checkout when the shipping address is a PO box and shows a message on the address field.
Minimum and maximum quantity per product
A Shopify validation Function that enforces a minimum and maximum order quantity per product, read from two product metafields. Tested JavaScript.
Require a minimum order value
A Shopify validation Function that blocks checkout below a minimum order value set in your store currency and converted for each market. Tested JavaScript.
Restrict products to tagged customers
A Shopify validation Function that lets only customers with a tag, such as trade or wholesale, check out with products that carry a restricted tag.
Discounts
Product, order and shipping discounts with the Discount Function API.
Tiered volume discount by quantity
A Shopify discount Function that gives 5%, 10% or 15% off a product as the customer buys 3, 5 or 10 of it. Tiers live in a metafield. Tested JavaScript.
Discount for customers with a tag
A Shopify discount Function that takes a percentage off the order for signed-in customers with a tag such as VIP or wholesale. Tested JavaScript.
Buy X get Y discount
A Shopify discount Function for buy X get Y offers: buy 2 of one product, get 1 of another free or discounted, cheapest first. Tested JavaScript.
Free shipping above a total, excluding a collection
A Shopify discount Function that gives free shipping above a cart total while products in excluded collections don’t count towards it. Tested JavaScript.
One discount Function, configured by metafield
A Shopify discount Function whose product and order discounts are set per discount in a JSON metafield, so one deploy serves many campaigns.
Free gift with purchase
A Shopify discount Function that makes one gift item free once the rest of the cart reaches a threshold. The gift must already be in the cart.
Cart transform
Expand bundles into their parts, merge lines into a bundle or change a line’s price.
Expand a bundle into its components
A Shopify cart transform Function that expands a bundle product into its component variants in the cart, using the standard component metafields.
Merge cart lines into a bundle
A Shopify cart transform Function that merges component lines into one discounted bundle line when the full set is in the cart. Tested JavaScript.
Personalization fee with lineUpdate
A Shopify cart transform Function that adds an engraving fee to the line price and title when a line item property is filled in. Shopify Plus.
Fulfillment constraints
Control which items ship together.
Keep pre-orders in a separate shipment
A Shopify fulfillment constraints Function that sends tagged pre-order items from a pre-order location and in-stock items from the others.
About the code
- Written for Function API version 2026-10 and checked against Shopify’s reference on the date shown. Shopify releases a new version every quarter.
- Custom apps that contain Functions only run on Shopify Plus stores; a public app with the same Function runs on any plan unless the page says otherwise.
- Every example ships with test fixtures, and we run them before publishing. Run them again after you change the code: shopify app function run.
- MIT license. Use the code in your own store or in client work.
Need this built, tested and maintained for your store? See Shopify Functions development.
Questions
- Do Shopify Functions need Shopify Plus?
- Only when they live in a custom app: custom apps with Functions run on Plus stores. The same Function in a public App Store app runs on any plan. A few features, such as B2B payment terms and the cart transform price update, are Plus only in every case; those pages say so.
- Why JavaScript and not Rust?
- JavaScript is easier to read and change, and it is fine for most carts. Shopify recommends Rust when a Function must handle very large carts within the instruction limit. The logic on these pages ports to Rust line by line.
- How do I install one of these Functions?
- Create an app with the Shopify CLI, generate a Function extension of the same type, replace its run.graphql, run.js and shopify.extension.toml with the files on the page, deploy the app and turn the customization on in the admin. Each page lists the steps.
- What replaced Shopify Scripts?
- Shopify Functions. Scripts stopped running on 30 June 2026. Line item scripts map to discount and cart transform Functions, shipping scripts to delivery customization and payment scripts to payment customization.
