Docs/Merchants/Program Protection
Cart validation rules
Cart validation rules let you put limits on how a product or collection can be bought. You can cap quantities, require a minimum cart amount, or reserve a product for customers with certain tags. When a cart breaks a rule, the customer sees the error message you wrote and can't complete checkout until the cart meets the rule.
Open the page
- In the Toki app, open Settings.
- Click the Cart Validation Rules tab.
If you haven't created any rules yet, the page shows Create your first cart validation rule with an Add rule button. Rules can limit purchases by product, collection, cart value, or customer tags.
Create a rule
- Click Add rule. A new card appears, numbered Rule 1, Rule 2, and so on.
- Under Applies to, choose Product or Collection.
- Pick the product or collection the rule applies to. This is required.
- Under Settings, check each restriction you want to apply. Each one opens its own fields, including an Error message.
- Click Save. Toki confirms with Cart Validation Rules Saved.
You can turn on several restrictions in the same rule, and you can create as many rules as you need. If Toki says Please review the highlighted fields, fix the highlighted fields and save again.
A rule that applies to a collection covers the products in that collection. Quantity caps count each product variant in the cart on its own: with Max number 2 on a collection rule, a customer can have up to 2 of each product variant from the collection in the cart.
Restrictions you can set
In this table, "the product" means the product, or the products in the collection, that the rule applies to.
| Setting | What it does |
|---|---|
| Limit number of products in the cart | Caps how many of the product a customer can have in the cart at one time. Enter the cap in Max number. |
| Limit total number of sales | Caps how many of the product one customer can buy in total, across all of their orders. Enter the cap in Max number. Available for product rules. |
| Minimum cart sub-total amount | The cart's sub-total must reach this amount before the customer can buy the product. Enter the amount in Minimum cart sub-total amount. |
| Minimum cart total amount | The cart's total must reach this amount before the customer can buy the product. Enter the amount in Minimum cart total amount. |
| Require customer tags | Only customers who have specific Shopify customer tags can buy the product. Enter one tag per line in Required customer tags. The customer needs every tag you list. |
The sub-total is the cart's amount before discounts and taxes. The total is the amount the customer pays, with discounts and taxes applied.
A few details to keep in mind:
- Limit total number of sales appears once you've picked a product. Toki keeps a running count of how many of that product each customer has bought, so the cap holds across orders. The count lives on the customer's account, so the cap is checked when the customer is signed in at checkout. If you switch the rule to Collection, this restriction is turned off and cleared.
- Require customer tags reads the tags on the customer's Shopify profile. A customer who isn't signed in at checkout sees the error message, because Shopify can't see their tags yet.
- Max number is at least 1. Amounts can include cents, for example 49.99.
- If you check a restriction but leave its value blank, Toki saves a default when you click Save: 1 for Max number and 0 for the minimum amounts. For Require customer tags, enter at least one tag.
Write the error message
Every restriction has its own Error message field. This is the text the customer sees when their cart breaks that restriction. Fill it in for every restriction you turn on. Keep it short and say what they need to change, for example:
- "You can add up to 2 of this item to your cart."
- "This item is available once your cart reaches $50."
- "This item is reserved for members. Log in to your member account to buy it."
What customers see at checkout
When a cart breaks a rule, Shopify shows your error message to the customer and holds the checkout until the cart meets the rule. Once the customer adjusts the cart, for example by lowering the quantity or adding more to reach the minimum, they can complete their purchase.
Connect the validation function
Your rules are applied at checkout by a validation function in your Shopify store. The Validation function card on the right side of the page has a Validation Function ID field: the ID of the Cart Validation Function that applies these rules. The ID is saved per store, so if you run several stores in Toki, each store has its own.
The ID belongs to the rule in your Shopify admin that uses Toki's Cart Checkout Validation function. In your Shopify admin, open Settings, then Checkout, and look in the Checkout rules section. Paste the rule's ID here once and save. From then on, each time you save this tab, Toki sends your current rules to that function.
If you're not sure what to enter here, chat with us and we'll set it up with you.
Edit or remove a rule
- Edit: change any field in the rule card, then click Save. Click Discard to throw away unsaved changes.
- Remove: click Remove at the top right of the rule card, then click Save. The rule stops applying once you save.
Advanced: show purchase counts in your theme
Once you pick a product or collection, the rule card includes a Metafield value and a Liquid example that a theme developer can use to show customers how many of the product they've already bought. Chat with us if you'd like help with this.