Menu Close

WooCommerce: Disable Payment Gateway by Country

default

You might want to disable PayPal for non-local customers or enable a specific gateway for only one country… Either way, this is a very common requirement for all of those who trade internationally.

Here’s a simple snippet you can further customize to achieve your objective. Simply pick the payment gateway “slug” you want to disable/enable (“paypal”, “authorize”, “stripe”, etc.) and the country code (US, ES, IE, etc.) and then apply your conditional rules in the plugin below.

Find payment gateway ID under WooCommerce > Settings > Payments

PHP Snippet: Disable Payment Gateway for Specific Billing Country

/**
 * @snippet       WooCommerce Disable Payment Gateway for a Specific Country
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 7
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
add_filter( 'woocommerce_available_payment_gateways', 'bbloomer_payment_gateway_disable_country' );
 
function bbloomer_payment_gateway_disable_country( $available_gateways ) {
    if ( is_admin() ) return $available_gateways;
    if ( isset( $available_gateways['authorize'] ) && WC()->customer && WC()->customer->get_billing_country() <> 'US' ) {
        unset( $available_gateways['authorize'] );
    } else {
        if ( isset( $available_gateways['paypal'] ) && WC()->customer && WC()->customer->get_billing_country() == 'US' ) {
            unset( $available_gateways['paypal'] );
        }
    }
    return $available_gateways;
}

Mini-Plugin: Business Bloomer WooCommerce Toggle Payments By Country

You don’t feel confident with coding? You need more control over your payment/country exclusions? You don’t want to purchase yet another bloated, expensive plugin? Great!

Business Bloomer WooCommerce Toggle Payments By Country is a mini WooCommerce plugin, without the usual hassles. One feature. Lifetime license. No annoying subscriptions. 1 plugin file. A few lines of code. No banners. No up-sells. No WP notifications. Use it on as many websites as you like. Lifetime support. 1-page documentation. A single and easy admin dashboard.

Screenshot of the settings:

Quick demo:

As you can see the settings are pretty straight forward. Select a payment method you wish to hide/show from the left, and the country that should trigger that from the right. Add more rules if needed. Simple!

Advanced “Payment Gateways by Country” WooCommerce Plugin

If you don’t feel 100% confident with coding, I decided to look for a reliable plugin that achieves the same result of this snippet (and more).

In this case, I found the WooCommerce Conditional Payment Gateways plugin to be the most complete when you need to enable/disable payment gateways based on certain criteria. You can create unlimited “rules” and use, for example, cart totals, billing country, shipping country, user role and much more to define which payment gateway shows and which not.

But in case you don’t want to use plugins and wish to code (or wish to try that), then keep reading 🙂

View Source
Posted in WooCommerce Tips