Examples
Ready-to-use function examples — order limits, address rules, tag-based restrictions, delivery and payment customizations.
Each example lists the category (which folder to create the function in), the family to pick, and any variables to set. Copy the code into the Functions Console editor, adjust, save and turn the function on.
Validation
Order value limit with a configurable threshold
Blocks checkout when the cart total exceeds a limit the merchant can edit on the dashboard — no code changes needed.
Category: Cart and checkout validation · Family: General
Function variables (the Function button in the editor toolbar):
{
"short_text#MAX_ORDER_TOTAL": "500",
"metadata": {
"MAX_ORDER_TOTAL": {
"subtype": "number",
"helpText": "Orders above this total are blocked at checkout"
}
}
}Code:
Currency-aware order limit
Applies the limit only when the buyer checks out in a specific currency.
Category: Cart and checkout validation · Family: General
Block PO boxes in the shipping address
Category: Cart and checkout validation · Family: Address
The error appears directly under the address field thanks to the target — see error targets.
Require login to buy gift cards
Category: Cart and checkout validation · Family: General
Quantity limit for tagged products
Limits products carrying a specific tag to 2 units per order.
Category: Cart and checkout validation · Family: Product
Query variables (the Query button in the editor toolbar):
Code:
Wholesale-only bulk orders
Requires a customer tag for quantities above 100.
Category: Cart and checkout validation · Family: Customer
Query variables: { "hasCustomerTags": ["wholesale"] }
Weight limit for subscription items
Blocks checkout when tagged subscription items weigh more than 10 kg in total. One-time purchases are not counted.
Category: Cart and checkout validation · Family: Selling plan
Query variables: { "hasProductTags": ["dog-food"] }
Collection minimum after all discounts
Category: Validation · Family: Discounts · Query variable inAnyCollection: ["gid://shopify/Collection/123456789"] · Code variable COLLECTION_MINIMUM
Blocks checkout when products from a collection add up to less than the minimum after product discounts and discount codes, excluding shipping. With a minimum of 50, two 26.00 items pass on their own (52.00) but are blocked with a 10% code (46.80).
Delivery customization
Hide express shipping for heavy carts
Category: Delivery customization · Family: General
Rename a delivery option for loyal customers
Category: Delivery customization · Family: Customer
Hide free shipping per delivery group
Category: Delivery customization · Family: Delivery groups · Query variable hasProductTags: ["collective"] · Code variables FREE_SHIPPING_THRESHOLD, FREE_SHIPPING_TITLE
Shopify Collective items ship in their own delivery group. This rule sums the discounted total of each group's own-brand lines and hides the free option in that group only when the total is under the threshold.
Payment customization
Hide Cash on Delivery for B2B buyers
Category: Payment customization · Family: Customer
Move a preferred payment method to the top
Category: Payment customization · Family: General
Discounts
10% off products with a tag
Category: Discounts · Family: Product
Query variables:
Code:
Free Express shipping for members
Category: Discounts · Discount classes: Shipping · Family: Tags
Gives customers tagged member 100% off every delivery option with "Express" in its title. In a split shipment, the Express option of every delivery group is discounted.
Query variables:
Code:
Order discount above a threshold
Category: Discounts · Family: General — set MIN_ORDER_TOTAL and ORDER_DISCOUNT_PERCENT as code variables.
Cart transform
Merge tagged products into a bundle
Category: Cart transform · Family: Tags
Query variables:
Code — set BUNDLE_PARENT_VARIANT_ID as a code variable (an existing, published variant that represents the bundle):
Time-based rules
Block checkout outside business hours
Category: Cart and checkout validation · Family: Time
Query variables:
Code:
timeAfter / timeBefore arrive as pre-computed booleans against the shop's local time — your code never parses dates. See Families and Variables for the date-time variants.
Last updated