Display rules are a set of conditions that can be set for sections & fields to control their display on the checkout page. This means you can set certain conditions for showing or hiding fields & sections on the checkout page.
This article will help you understand display rules settings and explain all the different types of conditions available for setting display rules.
In this article:
- General instructions to set display rules
- Conditions based on user role
- Conditions based on cart totals
- Condition based on shipping weight
- Conditions based on products & product variations
- Conditions based on product categories
- Conditions based on product tags
- Conditions based on product type
- Conditions based on shipping class
- Conditions based on other field's value
- Conditions based on input fields (Text, Hidden, Password, and Textarea)
- Conditions based on option value
- Based on the Checkbox
- Based on the Checkbox Group & Multi-Select
- Conditions based on Date Picker
- Conditions for country field
- Conditions for the state field
- Conditions based on the country field
- Conditions based on payment & shipping methods
- Custom conditions
General Instructions To Set Display Rules
This section will explain to you the common steps to set display rules.
To set display rules for checkout fields or sections:
- Navigate to the WooCommerce → Checkout Form → Checkout Fields page.
- Open the field/section property form popup.
- Click on the Add Field button to open the popup form if you are setting display rules for a new field.
- Click on the Edit Field button to open the popup form if you are setting display rules for an existing field.
- Click on the Add New Section button to open the popup form if you are setting display rules for a new section that you are creating.
- Click on the Edit Section button to open the popup form if you are setting display rules for an existing section.
- Navigate to the Display Rules tab from the popup.
- From this tab, you can define display rules. Here you can see two sets of rules, - one: Based on the Cart, User Roles and Product the other is Based on Checkout Fields. The first will be validated before loading the checkout page. And the other one will be validated once the page is loaded. You can add multiple conditions to each rule.
- From this tab, you can define display rules. Here you can see two sets of rules, the first one will be validated before loading the checkout page. And the other one will be validated once the page is loaded. You can add multiple conditions to each rule.
- Click on the AND or OR operator button to add multiple conditions and use these operators properly based on your requirement.
- Once the required conditions are added, click on the Save Field button to save the settings.
Conditions Based On User Role
Show or hide fields & sections based on user role. Below is the list of conditions available to display fields & sections based on the user role.
- User role equal to
- User role not equal to
Example #1: Show field xyz only for "Shop Manager"
Example #2: Hide field xyz for "Shop Manager" and "Administrator"
Conditions Based On Cart Totals
Show or hide fields & sections based on cart totals. Below is the list of conditions available to display fields & sections based on the cart totals.
- Cart total equal to
- Cart total greater than
- Cart total less than
- Cart subtotal equal to
- Cart subtotal greater than
- Cart subtotal less than
Example #1: Show field xyz if the cart total amount is between $100 & $500
Conditions Based On Shipping Weight
Show or hide fields & sections based on shipping weight. Below is the list of conditions available to display fields & sections based on the shipping weight.
- Shipping weight less than
- Shipping weight equal to
- Shipping weight greater than
Conditions Based On Products & Product Variations
Show or hide fields & sections based on products. Below is the list of conditions available to display fields & sections based on products in the cart.
- Cart contains
- Cart not contains
- Cart only contains
Example #1: Show field xyz if cart contains the product Cap
Conditions Based On Product Categories
Show or hide fields & sections based on product categories. Below is the list of conditions available to display fields & sections based on the categories of the products in the cart.
- Cart contains
- Cart not contains
- Cart only contains
Example #1: Show field xyz if the cart contains products only from the category Hoodies
Conditions Based On Product Tags
Show or hide fields & sections based on product tags. Below is the list of conditions available to display fields & sections based on the tags of the products in the cart.
- Cart contains
- Cart not contains
- Cart only contains
Example #1: Show field xyz if the cart has a product under the tag caps
Conditions Based On Product Types
Show or hide fields & sections based on product types. Fields or sections would be displayed based the type of product - Simple / Variable that is added in the cart.
Conditions Based On Shipping Class
Show or hide fields & sections based on shipping class.
Conditions Based On Other Field’s Value
This option allows you to set conditions based on other field’s value. Below is the list of conditions available to display fields & sections based on other fields’ value.
- Is empty
- Is not empty
- Value equals to
- Value not equals to
- Value in
- Contains
- Not contains
- Value greater than
- Value less than
- Value starts with
- Value not starts with
- Date equals to
- Date not equals to
- Date after
- Date before
- Day equals to
- Day not equals to
- Is checked
- Is not checked
- Match expression
Conditions Based On Input Fields (Text, Hidden, Password, and Textarea)
Follow the below steps for the field types like text, textarea, password, and hidden.
- Choose the Show/Hide option from the drop-down to display/hide the specific field.
- From the Select field textbox, choose a specific field based on which the rule needs to be set.
- Select the required condition from the next drop-down.
- Provide the conditional data that should be satisfied for that particular field.
- Save the changes made.
Conditions Based On Option Value
For Select and Radio
- Choose Show/Hide option from the drop-down to display/hide the specific field.
- From the Select box, pick the specific field based on which the rule has to be set.
- Choose the required condition from the next drop-down.
- Enter the option value in the input field at the right.
- Use the OR function to set condition rules based on more than one option text.
- Save the changes made.
Based On The Checkbox
Set display rules using the option 'Is checked/ Is not checked'. Follow the below steps to set a conditional field based on a checkbox.
- Choose Show/Hide from the drop-down to display or hide the field.
- From the Select box, pick the Checkbox field based on which the rule has to be set.
- Select the required condition Is Checked/Is not checked from the drop-down in the middle.
- Save the changes made.
Based On The Checkbox Group & Multi-Select
- Choose Show/Hide from the drop-down to display or hide the field.
- From the Select box, pick the field based on which the rule has to be set.
- Select a suitable condition from the drop-down in the middle.
- Enter the option value which needs to be satisfied for the field (Enter the value in the final input field.)
- Use the OR function to set condition rules based on more than one option text.
- Save the changes made.
Conditions Based On Date Picker
To set a rule based on the Date picker field type,
- Insert the date in the format ‘DD/MM/YYYY’.
- From the Select box, pick the field based on which the rule has to be set.
- Choose the required condition from the dropdown like ‘Day equals to/Day not equals to’.
- For setting a rule based on the day of a week enter the input values as the first three letters of the day after choosing the condition. (Example: MON instead of Monday).
Note: The date format set for the field/section in the field properties will not be validated while setting as the rule.
Conditions For Country Field
Setting display rules for the Country field is exactly the same as for other checkout fields. But this option is disabled by default, you have to enable it first.
To enable display rules for Country field:
- Navigate to Advanced Settings tab.
- Head to Other Settings section.
- Check the box Enable display of Country field based on Conditional rules.
Conditions For The State Field
Setting display rules for the State/ Province field is exactly the same as for other checkout fields. But this option is disabled by default, you have to enable it first.
To enable display rules for the State/ Province field:
- Navigate to Advanced Settings tab.
- Head to Other Settings section.
- Check the box Enable display of State/ Province field based on Conditional rules.
Conditions Based On The Country Field
Show or hide fields & sections based on the country field value. Below is the list of conditions available to display fields & sections based on the country field value.
- Value equals to
- Value not equals to
The option to set conditions based on Country Field value is disabled by default. To enable this option:
- Navigate to Advanced Settings tab.
- Head to Other Settings section.
- Check the box Enable conditional rules based on Country selected.
Note: Use the two-letter Country Code instead of Country Name for the conditions (Example: Use US for United States of America)
Example #1: Show field xyz only for United States of America (US)
Conditions Based On Payment & Shipping Methods
Show or hide fields & sections based on payment & shipping methods. Below is the list of conditions available to display fields & sections based on payment & shipping methods.
- Value equals to
- Value not equals to
The option to set conditions based on Payment & Shipping method is disabled by default. To enable this option:
- Navigate to Advanced Settings tab.
- Head to Other Settings section.
- Check the box Enable conditional rules based on Payment & Shipping methods.
Example #1: Show field xyz only if the selected shipping method is Free Shipping
Tip: You can inspect the page and point on the required payment method or shipping method to find its corresponding value in the source code.
Example # 2: Show field xyz only if the selected payment method is Direct Bank Transfer
Custom Conditions
When the above said out of the box options are not enough to set your required conditions, don’t worry you can set your own conditions using below hooks.
Filter hook to set custom display rules for checkout fields.
apply_filters('thwcfe_show_field', $show, $field_name);
Filter hook to set custom display rules for custom checkout sections.
apply_filters('thwcfe_show_section', $show, $section_name);
Comments
0 comments
Please sign in to leave a comment.