Each country or region uses different languages, and the online payment methods available in those places are often different as well. When building multilingual sites, we often need to disable certain payment methods for users in specific countries.
Set Different Payment Methods by User Country with a Plugin
Because users in different regions often rely on different payment methods, the available gateways also vary. For example, in China many users can pay with Alipay, WeChat Pay, or UnionPay. In the United States, users may prefer PayPal, Stripe, and similar gateways.
A plugin called Country Based Payments can help us implement this requirement. Simply install the plugin and configure it according to its documentation. I will not go into more detail here.
Display Different Payment Methods for Each Polylang Language
Because the payment methods available to users are often closely tied to the language they use, we can also configure the available gateways directly based on the user’s language.
In the following code, we use the current Polylang language to disable payment methods that should not be available for that language, which achieves exactly this goal.
add_filter('woocommerce_available_payment_gateways', function ($_available_gateways)
{
switch (pll_current_language()) {
case 'zh-hk':
unset($_available_gateways['wc_alipy']);
break;
case 'zh':
unset($_available_gateways['paypal']);
break;
default:
unset($_available_gateways['wc_alipay']);
}
return $_available_gateways;
});The implementation above mainly relies on WooCommerce’s woocommerce_available_payment_gateways filter. Based on the same principle, we can also control available payment methods according to other conditions, such as order amount or whether a discount is being used.
