Anchor to Cart and Checkout Validation Function APICart and Checkout Validation Function API
Cart and checkout validation implements checks and rules to ensure that orders meet specific criteria before allowing customers to proceed with their purchase. This includes express checkouts, such as Shop Pay, PayPal, Google Pay, and Apple Pay. To validate a cart and checkout, server-side, you can only use the Cart and Checkout Validation Function API.
Shopify Functions enables you to customize Shopify's backend logic. The Cart and Checkout Validation Function API integrates this logic into the checkout flow.
Use the API to generate the validations and to specify the message that should be displayed in checkout when the Function returns a validation error. You can specify the checkout fields to target with the validation error message, and the cart as a global object to target with a validation error message.
Anchor to Use casesUse cases
- Use tokengating or require a customer membership at checkout.
- Verify the age or ID of a customer when they proceed through checkout.
- Provide B2B product minimums, maximums, and multiples.
- Provide B2B location order minimums, maximums, or credit limits.
- Specify quantity limits in a flash sale.
The fetch target is limited to custom apps installed on Enterprise stores. You'll also need to request network access for Functions, as it's not currently available on development stores or in a developer preview.
Anchor to Getting startedGetting started
Scaffolding the Function using Shopify CLI will automatically configure your TOML file. You can alter the default configuration to customize the way your Function operates.
Anchor to TargetsTargets
A target is an identifier in shopify.extension.toml
that specifies where you're injecting code into Shopify Function APIs, or other parts of the Shopify platform. Each target is composed of three to four namespaces. The name begins with a broad Shopify context and ends with the behavior of the extensible element.
Anchor to Run targetRun target
cart.validations.generate.run
The run target generates cart and checkout validations using either Shopify data, hardcoded values, or fetch results from external providers. The target returns a list of operations to be applied to validations applied to the cart and checkout.
For example, you might use this to add a validation that, at checkout, confirms a customer's age meets the legal requirement to purchase a product in their cart.
- Anchor to InputInputOBJECT
The
Input
object is the complete GraphQL schema that your Function can receive as input to validate cart and checkout. Your Function receives only the fields that you request in the input query. To optimize performance, we highly recommend that you request only the fields that your Function requires.- Anchor to buyerJourneybuyer
Journey