Generate a cart and checkout validation Function extension via the Shopify CLI.
In `run.graphql`, declare the cart fields needed for your rule — line items, quantities, product metafields, buyer identity — keeping the query minimal to stay within the instruction budget.
In the Function `run` body, evaluate the rule (e.g., maximum quantity per SKU, restricted product combinations) and return a `FunctionRunResult` with a `errors` array when the rule is violated; each error requires a `localizedMessage` string and a target.
When the rule passes, return an empty `errors` array — the Function must always return a valid result, not throw.
Test on a dev store by adding products that trigger the validation; the checkout UI will display the localized error message and block the buyer from proceeding.
Use the Partner Dashboard Function traces to inspect the input payload and returned errors for debugging.
Known gotchas
Cart and checkout validation Functions run on every checkout interaction, not just at submission. Keep the Function logic fast and stateless — do not make network calls inside the Function runtime.
The `localizedMessage` field is displayed directly to buyers in the checkout UI; write clear, non-technical copy and validate the message in all locales you support.
Product metafields must be declared in the run.graphql query using their exact namespace and key; they are not available by default. Verify the metafield query syntax against current Function API docs.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp