Introduction
Conditional statements give you more granular control over the checkout process in WooCommerce and can help you fine tune the plugin to match your business processes and reduce fraud.
Conditional statements should be used when you want to add more advanced logic to the checkout page such as when to enable 3D secure or PayPal Credit.
Conditional statements are powerful and can be used for example, to display 3D Secure, based on the billing country that your customer has entered.
Note: PayPal credit is not available if there is a subscription product in the cart as PayPal vault flow must be used.
Before you can add your conditions, you must understand the syntax required for the conditions to work.
Symbols:
<
- the less than symbol is used to compare a value to another value. If the value on the left side of the symbol is less than the value on the right side of the symbol, true will be returned else false.
>
- the greater than symbol is used to compare a value to another value. If the value on the left side of the symbol is greater than the value on the right side of the symbol, true will be returned else false.
<=
- When the less than symbol is combined with an equal sign, then true will be returned if the value to the left of the symbol is less than or equal to the value right of the symbol.
>=
- When the greater than symbol is combined with an equal sign, then true will be returned if the value to the left of the symbol is greater than or equal to the value right of the symbol.
EQ
- Equal compares if two values are equal to one another. If both values are equal then true is returned, else false.
NOT EQ
- NOT EQ tests if the value is not equal to the compared value.
AND
- AND can be used to combine several conditions for more complex logic.
OR
- OR can be used to test different conditions sequentially.
IN
- IN is used to compare a value with a list of other values.
NOT IN
- NOT IN is used to determine if the given value is not in the list of compared values.
Available Values:
All dynamic values must be enclosed in curly brackets {} in order for conditions to be processed.
{amount}
- The total dollar amount in the shopping cart at the time the checkout page is shown.
{qty}
- The number of items in the shopping cart.
{currency}
- The currency that the customer's order is being processed in.
{b_country}
- The billing country that the customer specifies on the checkout page.
{s_country}
- The shipping country that the customer specifies on the checkout page.
Examples:
{amount} > 6.00
true is returned if the cart's amount is greater than 6 dollars.
{amount} > 6.00 AND {amount} < 125.00
true is returned if the cart's amount is greater than 6.00 dollars and less than 125.00 dollars.
{qty} EQ 2
true is returned if there are 2 items in the cart.
{amount} > 6.00 AND {qty} > 2
true is returned if the cart's amount is greater than 6 dollars and there are more than 2 items in the cart.
{currency} EQ USD
true is returned if the currency used to process the order is USD.
{currency} IN [USD, AUD, EUR, GBP]
true is returned if the currency matches any of the values contained within the brackets.
{currency} EQ USD OR ( {qty} EQ 2 AND {currency} EQ GBP )
true is returned if the currency equals USD or the quantity equals 2 and the currency is GBP.
{currency} NOT EQ USD
true is returned if the currency does not equal USD.
{currency} NOT IN [USD, GBP, EUR]
true is returned if the currency is not equal to any of the values supplied in paranthesis.
{b_country} NOT IN [US]
true is returned if the billing country is equal to any country other than the US.
Business Cases:
The following examples will demonstrate conditional statements that a merchant may want to add for their business processes. These examples will give you a firm grasp of how to maintain conditional settings for your site.
- Scenario: PayPal credit should only be offered when the shopping cart amount exceeds 300.00 and the currency is USD, GBP, or AUD.
-
Configure your conditional settings in the plugin's checkout settings page.
{amount} > 300 AND {currency} IN [USD, GBP, AUD]
- Checkout with a product that is less than 299 dollars, pounds, etc. Standard PayPal should be available.
- Change the product's price to something greater than 300.00. PayPal Credit will be available.
- Change the currency to EUR for the order, and standard PayPal will be displayed even though the amount exceeds 300.00 EUR. This is because in our condition, it was specified that PayPal credit would only be shown if the currency matched USD, GBP, and AUD.
-
- Scenario: We are a merchant that wants to provide 3D Secure for all transactions except those that have a billing country of the United States (US) or Australia (AU).
-
Configure your conditional settings in the plugin's checkout settings page.
{b_country} NOT IN [US, AU]
- Set the billing country on the checkout page to United Kingdom.
- Enter credit card information and click Place Order button. 3D Secure will be presented to the customer.
- Now change the billing country to US. 3D Secure will not be presented to the customer and the standard credit card payment process will be triggered.
-
Comments
0 comments
Please sign in to leave a comment.