Show Different WooCommerce Payment Gateways Based on Site Language

Different countries and regions often rely on very different online payment methods. When building a multilingual site, it is common to show different WooCommerce gateways to users based on the market they belong to.

Use a plugin to set gateways by country

When payment methods vary mainly by the visitor’s country, a plugin such as Country Based Payments can do the job. For example, users in China may need Alipay, WeChat Pay, or UnionPay, while users in the United States may be more likely to use PayPal or Stripe.

If country-based logic is enough for your store, installing and configuring that plugin is the simplest route.

Show gateways by Polylang language

In some stores, language is strongly correlated with the payment methods that should be available. In that case, you can use the current Polylang language to disable gateways that do not belong to that language.

add_filter('woocommerce_available_payment_gateways', function ($available_gateways) {
    switch (pll_current_language()) {
        case 'zh-hk':
            unset($available_gateways['wc_alipay']);
            break;

        case 'zh':
            unset($available_gateways['paypal']);
            break;
    }

    return $available_gateways;
});

This approach uses WooCommerce’s woocommerce_available_payment_gateways filter. The same principle can also be extended to other conditions, such as order amount, the presence of discounts, or customer roles.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *