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.

Delivery customization

Hide, rename or reorder the shipping options a customer sees.

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.

  • 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.

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 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.

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.

Have something to build? Let’s talk it through.

Taking a limited number of projects at a time. Every brief is read by an engineer, not a salesperson.

Gencer KarakayaShopify Engineer

An engineer reads your brief, and we reply by email.