- Why is conditional logic useful in my store?
- Conditional logic in the Flexible Checkout Fields plugin
- Condition Cart contains > Number of items
- Combining several conditional logic rules in one field
- Summary
Why is conditional logic useful in my store?
Conditional logic for WooCommerce checkout fields always has one primary purpose. The idea is that the store customer fills out only those fields that are actually necessary to complete the purchase. You will probably be discouraged if you feel that the store requires more information from you than necessary. Even if the mere fact of providing personal information does not discourage you, you will probably be discouraged by the feeling of wasting your time filling out a long form.
WooCommerce offers only one type of conditional logic here, and it is rather invisible at first glance. This happens when the cart contains only products that do not require shipping - then the shipping fields (those with the shipping prefix, e.g. shipping_first_name) are hidden. But that's it.
Conditional logic in the Flexible Checkout Fields plugin
Conditional logic is composed of two basic concepts - condition and action. If the condition is met, the action is triggered. In a WooCommerce checkout, an action usually means showing or hiding a field, or setting it as required.
If the cart contains a product from the Gifts for her category, show the Wrap as a gift checkbox.
The Flexible Checkout Fields plugin, from version 4.0.0, offers extensive conditional logic settings, including completely new conditions (marked in bold):
- Cart contains
- Product
- Category
- Product type
- Number of items (how many products are in the cart)
- Cart (what is the total value of the cart)
- FCF field (if the field added by the FCF plugin have the appropriate value)
- Shipping method
- Woo fields (if the field added by WooCommerce have the appropriate value)
- User (what is their role in the store)
- Payment method
- Date (what is the date and time of completing the form)
- FPF field (if the field added by the Flexible Product Fields plugin have the appropriate value)
Condition Cart contains > Number of items
Where did the idea to add the Cart contains > Number of items condition to the Flexible Checkout Fields conditional logic come from? These and other ideas (needs) are regularly reported to us by plugin users, and one scenario appeared very often.
Only virtual products - personalized tickets.
Additional information about the ticket holder - such as their name and e-mail address.
Saving this additional information with the order.
Conditional logic Cart contains > Number of items.
The Cart contains > Number of items condition allows you to perform the action if the number of products in the cart corresponds to the numerical values (x) given in the settings:
- Is (x)
- More than (x)
- Less than (x)
Setting up such conditional logic in the plugin panel is simple and comes down to configuring one line:
- Select a field (or add a new one), e.g. Name on ticket no. 1 and click the Conditional Logic tab.
- Click Group 1 - additional options will appear.
- Select an action, e.g. Show this field – additional options will appear.
- Set Rule #1 (first condition):
Cart contains > Number of items > More than > 0
If there is at least 1 product in the cart, the Name on ticket no. 1 field will appear in the checkout form.
The following fields are set similarly:
- Select a field (or add a new one), e.g. Name on ticket no. 2 and click the Conditional Logic tab.
- Click Group 1.
- Select an action, e.g. Show this field.
- Set Rule #1:
Cart contains > Number of items > More than > 1
If there is 1 product in the cart, the Name on ticket no. 1 field will appear in the checkout form.
If there are 2 products in the cart, the fields Name on ticket no. 1 and Name on ticket no. 2 will appear in the checkout form.
Combining several conditional logic rules in one field
Examples #2 and #3 describe a situation when all products in the store require additional information (always the same). However, it is possible that there are other products in the store that do not require providing a name and e-mail address - then showing the Name on the ticket field does not make much sense. In this case, an additional condition (Rule #2) will be necessary to exclude such products and narrow the scenario:
- Select the Name on ticket #1 field and click the Conditional Logic tab.
- Click Group 1.
- Click the And button in the Rule #1 row - additional options will appear.
- Set Rule #2 (second condition):
Cart contains > Category > Which is > Tickets
If there is at least 1 product in the cart and it contains a product from the Tickets category, the Name on ticket no. 1 field will appear in the checkout form.
Summary
The conditional logic of the Flexible Checkout Fields plugin includes all the basic components of a purchase form, such as: cart, shipping and payment methods, WooCommerce fields and user role. If we add further, less obvious (but useful) conditions, such as the FCF and FPF fields and the date, we get a complete tool that allows us to handle even the most complicated purchase scenarios, e.g. showing a field only to a user from a specific country (more on this topic in the article How to Add Conditional Logic to the Country Field in WooCommerce checkout).
Flexible Checkout Fields PRO WooCommerce £59
Edit, add new or hide unnecessary fields from the WooCommerce checkout form. Add pricing to fields and use conditional logic. It's all about conversions and better user experience. NEW: now you can set multiple conditions (OR) under one or more condition groups (AND).
💾 Active Installations: 90,000+ | WordPress Rating: