Build a Cart Transform Function that reads bulk-pricing tiers stored on each product metafield and applies the appropriate discount to each line. Display the tier thresholds and savings amounts in the cart drawer and on product pages so customers see the incentive to increase order quantity.
A wholesale-focused or high-volume DTC merchant needs to apply tiered discounts automatically as customers increase cart quantity, without requiring discount codes. The discount structure varies by product and should be stored centrally for easy management and real-time display.
Four pieces
Cart & Checkout
Bulk Tier Reader
Reads the bulk pricing tier data stored on each product and matches it against what is in the cart at checkout time.
Shopify Function + metafield
extensions/cart-transform/src/run.graphqlfunction
query Input {
cart {
lines {
id
quantity
merchandise {
__typename
... on ProductVariant {
id
title
product {
id
title
metafield(namespace: "bulk_pricing", key: "tiers") {
value
}
}
}
}
}
}
}
Store tiers as JSON in the metafield: [{"minQty": 5, "discountPercent": 10}, {"minQty": 10, "discountPercent": 15}]
Cart & Checkout
Tier Discount Logic
Calculates which tier each line qualifies for and computes the exact discount amount per item based on current quantity.
Function script
Storefront
Real-Time Cart Preview
Displays the exact savings at each tier as customers adjust quantity in the cart drawer or on product pages, making the discount structure transparent.