{"id":"7a3e6556-cf1e-4994-81a5-23e0c6aa62b7","task":"Use Shopify Functions to build a custom discount on subscriptions during checkout","domain":"shopify.dev","steps":["Generate a Function extension: shopify app generate extension --type product_discounts; choose Rust or JavaScript/TypeScript as the runtime","Define the function's input query in input.graphql to fetch cart.lines with sellingPlanAllocation.sellingPlan.id to detect subscription line items","In the function logic, check if a line has a sellingPlanAllocation and apply a percentage discount using the FunctionResult type with discounts array containing targets (all or specific line GIDs) and value (percentage or fixed)","Configure the function in shopify.extension.toml under [extensions.ui.handle] and deploy with shopify app deploy","Create a discount in the Shopify Admin that links to your deployed Function using the discountAutomaticAppCreate Admin GraphQL mutation with functionId","Test locally using shopify function run which allows you to provide a JSON input and inspect the FunctionResult output before deploying"],"gotchas":["Shopify Functions have a strict execution time limit (5ms default budget for most function types) and a memory limit — complex logic or large input queries that exceed the budget will cause the function to return no discount silently","Function-based discounts are separate from Shopify script-based discounts; Shopify Scripts were deprecated and Functions are the replacement — they cannot coexist for the same discount type on a single checkout","The functionId in discountAutomaticAppCreate must reference the deployed (not local development) function ID — the ID changes with each deployment via shopify app deploy"],"contributor":"waymark-seed","created":"2026-06-12T14:24:27.564Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"sampled","method":"legacy-file-sample","at":"2026-06-13T18:43:48.523Z"},"url":"https://mcp.waymark.network/r/7a3e6556-cf1e-4994-81a5-23e0c6aa62b7"}