Documentation for the Conditional Payment Methods for WooCommerce plugin.

Documentation for Conditional Payment Gateways for WooCommerce Plugin

Author: WPFactory PluginsVersion: 2.2.0Updated: 3 months ago
Requires WordPress version: 4.4Tested up to WordPress version: 6.4

Table of Contents

Settings

With Conditional Payment Gateways for WooCommerce plugin you can hide payment gateways in WooCommerce based on various conditions, for example, minimum or maximum cart amount, current date and time, current customer IP or user ID. Plugin supports all WooCommerce payment gateways including custom gateways.

Main Features

Currently plugin includes these modules (i.e. “conditions”):

  • Required or excluded date and time – Hides WooCommerce payment gateways by current date and time.
  • Required or excluded customer IP – Hides WooCommerce payment gateways by current user IP.
  • Required or excluded user – Hides WooCommerce payment gateways by current user ID.
  • Minimum or maximum cart total – Hides WooCommerce payment gateways based on minimum and maximum cart (i.e. order) amounts.

Options

Settings are located in “WooCommerce > Settings > Conditional Payment Gateways”.

Module Options

Each module (e.g. “Cart Total”, “User”, etc.) has two settings subsections (e.g. “Minimum Cart Total” and “Maximum Cart Total”), where you can set conditions for each payment gateway. Settings may slightly differ, but generally they are similar to this:

Date and Time Module Options

or this:

Cart Total Module Options

Besides setting conditions for each payment gateway, you can also enable/disable optional additional notices here. That is, in addition to hiding a gateway, you can also add extra notice on the checkout page. For example:

Currently "%gateway_title%" is not available.

or

Minimum amount for "%gateway_title%" is %value%. Your cart total is %result%.

You can use HTML and/or shortcodes in the notice content, e.g. [alg_wc_cpg_translate].

All modules have %gateway_title% placeholder. Some modules may have additional placeholders, for example, “Cart Total” module also has %value% and %result% placeholders.

Date/Time

Hides payment gateways by current date and time. Settings are located in “WooCommerce > Settings > Conditional Payment Gateways > Date/Time”.

Options must be set as date range(s) in from-to format, i.e. dates must be separated with the hyphen - symbol.

You can add multiple date ranges, one per line (algorithm stops on first matching date range), i.e.:

from1-to1
from2-to2

Dates can be set in any format parsed by the PHP strtotime() function, except you can’t use hyphen - symbol, as it’s reserved for separating from and to values.

You can use shortcodes when setting the values.

Customer IP

Hides payment gateways by current customer IP. Settings are located in “WooCommerce > Settings > Conditional Payment Gateways > Customer IP”.

Options must be set as list of IPs, one IP per line, e.g.:

127.0.0.1
172.16.0.9
192.0.0.7

You can use shortcodes when setting the values.

User

Hides payment gateways by current user ID. Settings are located in “WooCommerce > Settings > Conditional Payment Gateways > User”.

Options must be set as list of user IDs, one per line, e.g.:

100
101
122

For guests, i.e. not logged in users, use 0.

You can use shortcodes when setting the values.

Cart Total

Set minimum and/or maximum order amounts for each payment gateway. Settings are located in “WooCommerce > Settings > Conditional Payment Gateways > Cart Total”.

If set to zero – option is ignored.

For decimal values use dot . symbol.

In “Additional notice”: %result% will output current cart total, and %value% will output current gateway min or max amount.

You can use shortcodes when setting the values.

In addition to common module options, this module has “Cart Total Calculation” option. It sets how cart total should be calculated, when checking conditions in the current module. You should use [alg_wc_cpg_cart_total] shortcode here. For example:

[alg_wc_cpg_cart_total exclude_taxes="yes" exclude_shipping="no" exclude_discounts="no"]

General Options

Conditional Payment Gateways for WooCommerce - General Options

Debug
Will add a log to “WooCommerce > Status > Logs”.
Default: no
Leave at least one gateway
Will ensure that when all payment gateways do not match “enabled” criteria, one last remaining gateway will still remain active in any case.
Default: no
Notice styling
Will be used for all additional (optional) notices. Possible values: Notice; Error; Success.
Default: Notice

 


Shortcodes

 

Shortcodes

Plugin includes these shortcodes:

[alg_wc_cpg_if]

[alg_wc_cpg_if] shortcode can be used for the conditional output.

For example, if you need to use different min or max amounts depending on current user ID, you can add something like this to the “Cart Total” module. Let’s say you want to set min amount for user with ID 123 to $10.50, and for all other users to $15.50. In this case, you would need to set the “Minimum Cart Total” option to:

[alg_wc_cpg_if value1="{alg_wc_cpg_user_id}" value2="123" operator="equal" then="10.50" else="15.50"]

Shortcode support these attributes:

Required attributes

value1 – first value for the comparison. Can contain shortcodes – in this case you need replace square brackets [,] with curly brackets {,}, and if you need to add attributes to the shortcode, make sure you alternate double " and single ' quotes, e.g.:

[... value1="{alg_wc_cpg_cart_total exclude_taxes='no'}"...]

value2 – second value for the comparison. Can contain shortcodes – check value1 description.

operator – comparison operator. Available operators:

equal
greater_than
less_than
greater_than_or_equal
less_than_or_equal
not_equal
between
between_or_equal

When using between or between_or_equal operators, you need to set value2 attribute as comma-separated list of two values. For example, let’s say you want to disable some gateway for user with IP 172.16.0.9, but only if cart total is between $10 and $50. In this case, you would need to set “Customer IP > Exclude Customer IP > Your gateway” to:

[alg_wc_cpg_if value1="{alg_wc_cpg_cart_total}" value2="10,50" operator="between" then="172.16.0.9"]
Optional attributes

then – outputted on successful comparison. Can contain shortcodes – check value1 description.

else – outputted on failed comparison. Can contain shortcodes – check value1 description. Default value is empty string.


[alg_wc_cpg_cart_total]

[alg_wc_cpg_cart_total] shortcode calculates cart total.

Shortcode support these attributes:

exclude_taxes – should we exclude taxes when calculating cart total. Default value: yes

exclude_shipping – should we exclude shipping when calculating cart total. Default value: no

exclude_discounts – should we exclude discounts when calculating cart total. Default value: no

Example
[alg_wc_cpg_cart_total exclude_taxes="yes" exclude_shipping="no" exclude_discounts="no"]

[alg_wc_cpg_user_id]

[alg_wc_cpg_user_id] shortcode retrieves current user ID.

Shortcode has no available attributes.


[alg_wc_cpg_translate]

[alg_wc_cpg_translate] shortcode is used for WPML and Polylang translations.

[alg_wc_cpg_translate lang="EN,DE" lang_text="EN & DE text" not_lang_text="Text for other languages"]
[alg_wc_cpg_translate lang="EN,DE"]EN & DE text[/alg_wc_cpg_translate][alg_wc_cpg_translate not_lang="EN,DE"]Text for other languages[/alg_wc_cpg_translate]