Fail Validation Action
The Fail Validation action allows you to prevent customers from placing an order with an error message targeted at a specific field. This ensures data integrity, enforces business rules, and prevents invalid orders from being placed.
Purpose
This action prevents checkout completion when specific conditions aren’t met, displaying custom error messages to guide customers in resolving issues. It’s essential for:
- Enforcing business rules
- Preventing invalid orders
- Protecting inventory
- Ensuring compliance
- Improving data quality
Error Message Configuration
Message Properties
- Error Text: The message displayed to the customer
- Field Target: Which checkout field to highlight
- Language: Localized message support
Field Targets
Error messages can be attached to:
- Cart Level: General cart validation
- Line Items: Specific product issues
- Quantity Fields: Quantity-related errors
- Delivery Address: Shipping restrictions
- Delivery Method: Shipping option issues
- Payment Method: Payment restrictions
- Discount Code: Coupon/discount issues
- Customer Info: Account-related validations
Validation Rules
Product Validations
- Minimum/maximum quantity per product
- Product availability by location
- Product combination restrictions
- Age-restricted products
- Prescription requirements
- License verification
Cart Validations
- Minimum/maximum order value
- Total item count limits
- Mixed cart restrictions
- Category combination rules
- Weight/dimension limits
Customer Validations
- Account status verification
- Customer segment restrictions
- Purchase history requirements
- Membership validation
- Credit limit checks using metafields
Location Validations
- Shipping restriction by region
- Product availability by location
- Service area boundaries
- International restrictions
- Hazmat shipping rules
Message Formatting
Dynamic Variables
Include dynamic information in messages:
{product_name}- Product causing the issue{quantity}- Current quantity{max_quantity}- Maximum allowed{min_amount}- Minimum required{difference}- Amount needed
Localization
Multi-Language Support
Provide translations for international customers:
EN: "Minimum order value is $50"
FR: "La valeur minimale de commande est de 50 $"
ES: "El valor mínimo del pedido es de $50"
Regional Variations
Adjust messages for different regions:
US: "Zip code required"
UK: "Postcode required"
CA: "Postal code required"
Limitations
- Cannot modify cart contents (only validate)
- Message length is limited
- Validations run at specific checkout points
- Cannot validate external systems in real-time
Regular Expressions
String conditions in validation functions support regular expression matching. Use the RegExp (case-sensitive) or RegExp* (case-insensitive) operators to match patterns in text fields like addresses, SKUs, or customer notes.
See the Regular Expressions reference for supported syntax and examples.
Ignore Case and Spaces
Use Equals (ignore case and spaces), Does not equal (ignore case and spaces), Contains (ignore case and spaces) and Does not contain (ignore case and spaces) to compare text that customers type in different ways. SW1A 1AA equals sw1a1aa. In an Advanced Condition, the same operators are ~=, !~=, ~*= and !~*=, and they compare two fields, for example a cart attribute with Delivery Address: First Name. Use join text (+) to compare a full name or a two-line address.
See Ignore Case and Spaces for the rules and an example that keeps a gift recipient’s address with Apple Pay and Google Pay.
Prices After All Discounts
Three fields give the price that the customer pays for the products, after all discounts:
- Line Price After All Discounts: the price of one unit of a cart line after every discount on the line, including its share of order discounts.
- Cart Subtotal After All Discounts: the total of all cart lines at these prices.
- Group Subtotal After All Discounts: the total of the cart lines in the line groups that you select.
The fields include product discounts and order discounts: discounts from Function Studio, from other apps and Shopify discount codes. Shipping and tax are not included. A free gift with a 100% discount counts as 0.
Use cases:
- Give a free gift only when the other products cost more than $100 after discounts.
- Block checkout when a discount code takes the order below a minimum value.
- Keep a minimum order value that counts the price after discounts, not the price before discounts.
Availability
- The fields are available in validation functions only. A discount function cannot see other discounts.
- They need the function input Member entitlement input. The app selects it when you use one of these fields. After you save, make sure that Function Input shows Member entitlement input.
- They work on all Shopify plans. The validation reads the discounts from checkout itself.
Example: free gift above $100 after discounts
Define the groups
Add a Define line groups block with a group for the paid items and a group for the gift.
Add the condition
Add a Check if… block with Group Qty of the gift group greater than 0 AND Group Subtotal After All Discounts of the paid items group less than or equal to 100.
Add the action
Under Then, add Fail Validation with a message, for example “The free gift needs more than $100 of products after discounts.”
Save
Save the function and check the function input.
Exactly $100.00 does not qualify in this example. Use “less than 100” if $100.00 must qualify.
Test in the Cart Tester
When the function uses one of these fields, each cart line in the Cart Tester has a Line discount field. Enter the total discount on the line for all units, including its share of order discounts. Leave it empty for no discount.
Note
When a discount applies to only some units of a line, for example one free unit, checkout splits the line in two. The app counts each discount one time.