Contents
Introduction
Welcome to the Checkout Fields for Blocks - Conditional Logic Add-on documentation. This plugin enhances the Checkout Fields for Blocks fields by allowing dynamic, condition-based interactions. The core feature of this plugin is its powerful Conditional Logic, enabling you to show or hide fields based on specific conditions.
Requirements
The Checkout Fields for Blocks - Conditional Logic Add-on plugin requires the free Checkout Fields for Blocks plugin in version 1.1 to work.
Installing the Plugin
To get started with the plugin, follow these steps:
- Download the Plugin from My Account.
- Upload the Plugin:
- Navigate to the Plugins section in your WordPress admin panel.
- Click on Add New > Upload Plugin and select the ZIP file.
- Click Install Now and then Activate the plugin.
Overview
Conditional logic allows you to show or hide checkout fields based on specific conditions. This means you can create dynamic checkout forms that adapt to the user’s selection or cart content, offering a more personalized experience for your customers.
Setting Up Conditional Logic
- Navigate to Checkout Site edition: Go to Pages > Page Name.
- Choose checkout form field to edit.
- Enable Conditional Logic: For each field you want to apply conditional logic to, check the box labeled Enable Conditional Logic.
- Configure the Condition: Once enabled, you’ll need to define the conditions under which the field should be displayed.
Types of Conditions
The plugin allows you to create various conditions that control whether a field should be visible or hidden. Here are the most common types of conditions:
1. Product-Based Conditions
Condition: Show the field if a specific product is in the cart.
Example: Only display a gift message field if a certain product (like a gift) is in the cart.
Operator:
- Contains: The field will be shown if the cart contains the selected product.
- Does not contain: The field will only appear if the product is not in the cart.
2. Shipping Method Conditions
Condition: Show the field if a specific shipping method is selected.
Example: Only display a "Rush Processing" field if the customer selects the express shipping option.
Operator:
- Is: Shows the field when a specific shipping method is selected.
- Is not: Shows the field when the selected shipping method is not the one specified.
3. Payment Method Conditions
Condition: Show the field based on the selected payment method.
Example: Display a field asking for a credit card number only if the customer selects a card payment method.
Operator:
- Is: Displays the field when the chosen payment method matches the selected one.
- Is not: Hides the field if the payment method doesn't match the selected one.
4. Cart Total Conditions
Condition: Display a field based on the cart total.
Example: Only show the "Add a note" field if the cart total exceeds a certain amount.
Operator:
- Greater than: Show the field when the cart total exceeds a certain value.
- Less than: Show the field when the cart total is below a specified amount.
- Equals: Show the field only when the cart total matches a specified amount.
5. User Role Conditions
Condition: Show the field if the customer is logged in and has a specific role.
Example: Display a special discount field for users with the “VIP” role.
Operator:
- Is: The field will only show if the logged-in user has the specified role.
- Is not: The field will appear only if the user does not have the specified role.
6. Date Conditions
Condition: Show the field based on the current date.
Example: Display a special promotion field only on specific dates (e.g., during Black Friday).
Operator:
- Before: The field will show if the current date is before the specified date.
- After: The field will show if the current date is after the specified date.
7. Field-Based Conditions
Condition: Show the field based on the value of another field on the checkout page.
Example: Only display the "Message" field if the user has selected a certain option in another field.
Operator:
- Is: Show the field when the condition field matches the specified value.
- Is not: Show the field when the condition field does not match the specified value.
8. Cart Contains Specific Category Conditions
Condition: Show the field if the cart contains a product from a specific category.
Example: Display a warranty field if a product from the "Electronics" category is added to the cart.
Operator:
- Contains: The field will be shown if the cart contains a product from the specified category.
- Does not contain: The field will only appear if the product from the specified category is not in the cart.
9. Customer Location Conditions
Condition: Show the field based on the customer's billing or shipping address (e.g., country or state).
Example: Show a field only for customers from a specific country or state.
Operator:
- Is: Show the field if the location matches the specified value.
- Is not: Show the field if the location does not match the specified value.
10. Cart Contains Specific Attribute Conditions
Condition: Show the field if the cart contains a product with a specific attribute (e.g., color, size).
Example: Show a field for selecting engraving text only if a product with the "Personalization" attribute is in the cart.
Operator:
- Contains: Show the field if the cart contains a product with the specified attribute.
- Does not contain: Show the field if the cart does not contain a product with the specified attribute.
Operators in Conditional Logic
Here is a list of the available operators that you can use to create conditions:
1. Is
Compares the value of a field to a specified value. The field will be displayed if the condition matches.
2. Is not
Checks if the value of the field is different from the specified value. The field will only be displayed if the condition does not match.
3. Greater than
Checks if the value is greater than a specified value. The field will be displayed if the condition is met.
4. Less than
Checks if the value is smaller than a specified value. The field will be displayed if the condition is met.
5. Equals
Checks if the value is exactly equal to a specified value. The field will only be displayed when the condition is exactly matched.
6. Contains
Checks if the field contains a certain value. The field will be shown if the condition is satisfied.
7. Does not contain
Checks if the field does not contain a certain value. The field will be displayed if the condition is met.
Combining Conditions with AND/OR Logic
You can combine multiple conditions to create more complex logic using AND and OR operators.
- AND: All conditions must be true for the field to be displayed.
Example: Show a field only if both a product is in the cart and a specific shipping method is selected. - OR: The field will display if at least one of the conditions is true.
Example: Show a field if either the cart contains a specific product or the total exceeds a set amount.
Example Use Case
Imagine you have a WooCommerce store selling electronics. You can create the following conditional logic:
- If the cart contains a product from the “Laptop” category and the customer selects “Express Shipping”, show a checkbox asking if they want to add extended warranty for a fee.
Troubleshooting
Issue: Checkout Fields Are Not Displaying
Solution: Ensure that the fields are enabled and that conditional logic is correctly set. Check if there are any conflicts with other plugins.