Display Rules

Display rules are a set of conditions which can be set for fields & sections to control their display in the checkout page. You can display fields and sections conditionally. Which means you can set certain rules for showing or hiding fields & sections.

There are multiple types of conditions available which can be applied for your checkout field and sections. Below are the available options to set conditions, each of these options is explained in detail with examples later in this article.

  • Based on user roles: This option allows you to set conditions based on the user role.
  • Based on cart totals: This option allows you to set conditions based on Cart Total and Cart Subtotal.
  • Based on product category: Set conditions based on product categories.
  • Based on product tags: Set conditions based on product tags.
  • Based on product: Set conditions based on products.
  • Based on product variation: Set conditions based on products variations.
  • Based on other field values: Set conditions based on the other field's values.
  • Custom condition: When the above options are not enough for your requirement, you can define your own conditions with the help of the provided hook.

General instructions to set display rules.

This section will explain you the common steps to set display rules.

To set display ruled for checkout fields or sections:

  1. Navigate to WooCommerce → Checkout Form → Checkout Fields page.
  2. 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.
  3. Navigate to the Display Rules tab from the popup.
  4. 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.
  5. Click on the AND or OR operator button to add multiple conditions and use these operators properly based on your requirement.
  6. 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 are the list of conditions available to display fields & sections based on the user role.

  1. User role equal to
  2. 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 are the list of conditions available to display fields & sections based on the cart totals.

  1. Cart total equal to
  2. Cart total greater than
  3. Cart total less than
  4. Cart subtotal equal to
  5. Cart subtotal greater than
  6. Cart subtotal less than

Example #1: Show field xyz if the cart total amount is between $100 & $500

Conditions based on products

Show or hide fields & sections based on products. Below are the list of conditions available to display fields & sections based on products in the cart.

  1. Cart contains
  2. Cart not contains
  3. Cart only contains

Example #1: Show field xyz if cart contains the product Cap

Conditions based on product variations

Show or hide fields & sections based on product variations. Below are the list of conditions available to display fields & sections based on product variations in the cart.

  1. Cart contains
  2. Cart not contains
  3. Cart only contains

Example #1: Show field xyz if cart contains the product T-Shirt of size Medium

Please refer below screenshot to find the Variation Id.

Conditions based on product categories

Show or hide fields & sections based on product categories. Below are the list of conditions available to display fields & sections based on the categories of the products in the cart.

  1. Cart contains
  2. Cart not contains
  3. Cart only contains

Example #1: Show field xyz if cart has a product of the category Hoodies

Conditions based on product tags

Show or hide fields & sections based on product tags. Below are the list of conditions available to display fields & sections based on the tags of the products in the cart.

  1. Cart contains
  2. Cart not contains
  3. Cart only contains

Example #1: Show field xyz if cart has a product under the tag Party Wear

Conditions based on other field’s value

This option allows you to set conditions based on other field’s value. Below are the list of conditions available to display fields & sections based on other fields’s value.

  1. Is empty
  2. Is not empty
  3. Value equals to
  4. Value not equals to
  5. Value in
  6. Contains
  7. Not contains
  8. Value greater than
  9. Value less than
  10. Value starts with
  11. Value not starts with
  12. Date equals to
  13. Date not equals to
  14. Date after
  15. Date before
  16. Day equals to
  17. Day not equals to
  18. Is checked
  19. Is not checked
  20. Match expression

Conditions for Country field

Setting display rules for 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:

  1. Navigate to Advanced Settings tab.
  2. Head to Other Settings section.
  3. Check the box Enable display of Country field based on Conditional rules.

Conditions for state field

Setting display rules for 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 State/ Province field:

  1. Navigate to Advanced Settings tab.
  2. Head to Other Settings section.
  3. Check the box Enable display of State/ Province field based on Conditional rules.

Conditions based on country field

Show or hide fields & sections based on the country field value. Below are the list of conditions available to display fields & sections based on country field value.

  1. Value equals to
  2. Value not equals to

The option to set conditions based on Country Field value is disabled by default. To enable this option:

  1. Navigate to Advanced Settings tab.
  2. Head to Other Settings section.
  3. Check the box Enable conditional rules based on Country selected.

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 are the list of conditions available to display fields & sections based on payment & shipping methods.

  1. Value equals to
  2. Value not equals to

The option to set conditions based on Payment & Shipping method is disabled by default. To enable this option:

  1. Navigate to Advanced Settings tab.
  2. Head to Other Settings section.
  3. Check the box Enable conditional rules based on Payment & Shipping methods.

Example #1: Show field xyz only if the selected shipping methode is Free Shipping

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);