How to build validation rules
In this article, we're going to explore the Rules Builder and learn how to build validation rules for your campaigns.
- Create validation rules
- Create validation rules with metadata
This article shows how to build a validation rule and add validation rules to a campaign. Visit this article to see a complete list of limits and rules that you can create with the Validation Rules Builder.
Rules Builder overview
In this section, you'll see how to use Rules Builder and create validation rules. There are two ways you can access the Rules Builder and create validation rules:
- The dedicated Validation Rules section in the dashboard lets you prepare rules for future use.
- When creating/editing campaigns in the Campaign Manager, you can create validation rules and assign them to the campaign right away.
To open the Builder in the Validation Rules section, click the plus.
Step 1: Name the rules
Add a name for your validation rule/set of rules. They will be automatically saved in the dashboard.
Step 2: Choose between basic and advanced Builder
The Builder has two modes: basic and advanced. Choose the basic Builder to see a shortcut to the most common rules and create popular limits. Choose the advanced Builder to see all possible validation rules you can create.
In the Campaign Manager, you'll see the basic Builder by default. You can switch to the advanced mode to see all available rules.
Step 3: Define the context
Validation rules context defines the purpose of validation rules and their future usage. If you want to use the rules in more than one context or campaign type, choose General Usage.
In the Campaign Manager, you don't need to set up the context. It is set accordingly to the created campaign type.
Step 4: Create validation rules
There are two components in the Rules Builder:
- The first lets you select which items the discount or gift card can be applied to and which items the discount/gift card can't be applied to.
- The second component enables you to create limits that need to be met to make a successful redemption or earn loyalty points.
Select discounted (included) and excluded products
Selecting discounted or excluded items doesn't define required cart items, but defines which items the discount or gift card will be applied to if all validation rules are met.
First, you can choose between Discount Each or Discount Selected. If you choose to discount each, a discount or gift card will be applied to every order line item in the cart, except for the items defined in excluded products.
- Select existing products from your list.
- Create a products collection(s) that defines what criteria items have to match to qualify for a discount.
- Choose from existing product collection(s).
Select products from your list
Select discounted items from products previously added to your account.
Confirm with Select products.
Create a dynamic collection with filters
Follow this tutorial to learn how to create product filters and collections.
Create criteria for discounted items by using filters and assign them to a dynamic collection. As a result, each item from the cart will be validated against collection rules. If it matches the collection criteria, the discount will be applied to the item. In this case, products don't have to be added to your account to be validated and discounted.
Step 1: Define criteria for discounted products
Click Find and apply filters.
Choose one of the standard product attributes or switch to Custom attributes to create filters with metadata.
Create criteria for discounted products using available operators. Click the plus to add the filter.
Confirm added filters with Apply.
Note that you can combine many standard and custom filters in one product collection. Using OR/AND you can define if an item needs to match all added filters or only one of them.
Choose Apply when all filters are set.
Step 2: Assign filters to a new dynamic collection
Click Create dynamic collection to assign the filters to a new product collection.
Provide the collection name and confirm with Save. You can select more than one product collection that defines the criteria for discounted products. When you add all needed collections, confirm with Select collection(s). As a result, only items that match the criteria of the selected collection will be discounted.
Select from existing product collections
If you prepared collections beforehand, you can use them when defining discounted or excluded items. Next to selecting particular items, you can also choose to discount existing product collections:
- Switch to collections view (1).
- Select the collection from the list (2).
- Confirm with Add (3), note that you can add more than one collection to discounted products.
- When ready, confirm with Select collection(s) (4).
Likewise, you can use the same methods to define excluded products. As a result, the discount won't be applied to the selected items.
- If you choose to discount a product collection and add one of its items to excluded products, the discount will be applied only to collection items that are not selected in excluded products.
- If the rules will try to force both applying the discount and excluding the same product, the discount won't be applied to this item (it'll be excluded during the redemption). The excluded products rule has priority over included products rule.
Adding product to the static collection equals adding all product SKUs to the static collection. When it comes to the dynamic collections, if the product matches collection filters, only the product enters the collection, SKUs are validated against filters and need to match them to enter the dynamic collection.
Validation rules limiting redemptions
Validation rules that you can create below the discounted/excluded items can be assigned to incentives (discounts, coupons, gift cards, digital rewards, referral codes), and earning rules. If you attach validation rules to discounts or campaign codes, they will limit their redemptions. If you assign validation rules to the earning rules in your loyalty campaign, they will define circumstances that trigger the assignment of new loyalty points. You can create limits for redemptions and earning rules using the basic or advanced Builder.
Basic rules builder
Choose a rules category and define the limit by using available conditions.
Here's a list of basic rules related to:
- Customer activity that enables you to target specific customer segments and/or exclude particular segments from your promotion.
- Attributes match – order, products, and redemption metadata. In this section, you can build limits based on custom metadata attributes. Please note that you should define these attributes in the metadata schema first. Click here to learn more.
- Budget rules that set the limits described in the reference under BUDGET CONSTRAINS.
- Order-related rules that model required cart structure and volume.
Advanced rules builder
Define the logic between rules (1). Additionally, you can specify a fallback error message that will be used when there is no error message defined for the particular rule (2).
Expand the rules from the category you're interested in and build a restriction using available operators.
Confirm each rule with Add. All active rules will be visible on the grey background below each category.
Step 5: Confirm and save rules
When rules are added, click Save to confirm. Saved rules will be visible in the main list in the Validation Rules.
You can edit or remove created validation rules, but note that deleting the rules won't be possible as long as they're attached to any of your existing campaigns or rewards.
Custom validation rules with metadata
Metadata enables you to add custom attributes to your Voucherify project. Metadata added to products, customers, orders, and redemptions can be used when creating validation rules. Supporting many metadata types and validation operators gives you flexibility in creating custom limits and rules which aren't available out-of-the-box.
Product metadata in the Rules Builder has two goals:
- You can define custom attributes that qualify or disqualify a product from applying the discount or gift card. Go here for the detailed instructions.
- You can also define the required cart structure. It comes down to defining what custom attributes items in a customer's cart need to have or can't have to redeem the code/ earn loyalty points. On top of added metadata, you can set additional criteria for matching items like items count, and subtotal.
Create order structure validation rules with metadata
Step 1: Go to the Rules Builder and expand Order structure validation rules.
Step 2: Decide if the metadata has to be attached to every, any, or none of the order line items. Mark the respective checkbox.
Step 3: Click Add to build filter(s) with metadata added previously to metadata schema.
Step 4: When creating filters, you can combine many metadata and standard attributes. After you add all filters, click Create dynamic collection. The collection will save added filters to validate each order line item coming with requests. Only items that meet collection criteria will join the collection list.
You can also define the required price and quantity of every/any matching order line. Please note that for ANY order item rules, each sub-rule can be matched by a different order line item.
"AND" means that both rules need to be met. "AND" doesn't mean both rules need to be met by the same order line. If each rule will be met by a different order line item, validation will succeed.
- Every item in the cart needs to have metadata category is spring_sale and metadata vendor Levi's or Guess.
- At least one item in the cart needs to have a metadata category is new_in_stock and the subtotal of matched items needs to be more than $100.
- None of the items in the cart can have a metadata category is premium.
To create a custom limit with customer, redemption, and order metadata, follow the steps below:
- Add new metadata definition to the respective metadata schema.
- Open advanced Rules Builder in the Validation Rules menu or in the Campaign Manager.
- Expand the rules from a chosen category, build the rule with metadata and available conditions.
- Confirm with Add.
Take a look at the examples below to see popular validation rules with metadata.
Customer metadata satisfy
Go to Validation rules > Audience.
You can use attributes added to the Customer schema to create additional customer-related rules.
- Only customers with metadata customer_lifetime_value is more than 2000 can redeem the discount.
- Customers with metadata billing_unpaid is true cannot redeem the discount.
- Customers with metadata subscription is premium can redeem gift cards from campaign X.
Order metadata satisfy
Go to Rules Builder > Order structure
Orders enable you to pass your transactional data to Voucherify. Using order metadata and validation rules, you can define additional conditions that the customer's order has to match to redeem incentives or earn loyalty points.
- Voucher can be redeemed only if metadata Shipping_postal_code starts with 43-.
- Customer gets 50 loyalty points if the order total amount is more than $100 and metadata shipped is true.
- Customers get - 50% if the order metadata takeaway is false and - 25% if metadata takeaway is true.
- Customers get extra 100 loyalty points if the order was placed in July between 10 AM and 1 PM (metadata booking_date is within time-frame 6/1/2021 - 6/30/2021 Every day 10:00 AM to 1 PM).
Redemption metadata satisfy
Go to Rules Builder > Advanced.
You can attach metadata to redemption requests. Redemption metadata in validation rules lets you define additional attributes that need to be passed to successfully redeem codes/promotions.
- Voucher can be redeemed only if metadata payment_method is credit_card.
- Customer can redeem a $10 gift card if the metadata booking_channel is homepage.
- Customers get a free item X (unit discount) if redemption was made in July between 10 AM and 1 PM (metadata booking_date is within time-frame 6/1/2021 - 6/30/2021 Every day 10:00 AM to 1 PM).