Skip to main content

Quick and easy example of how to disable payment gateways based on the Country in WooCommerce.  Currently there isn’t an easy way to do this through the WooCommerce settings so you’ll need to open up your code editor.

Navigate to your theme folder at /wp-content/themes/themename .  Hopefully you’re using a child theme so jump into that theme’s folder and look for your functions.php file.  Scroll down to the bottom and drop in this snippet.

If you’re using WooCommerce 3.0 or newer:

function payment_gateway_disable_country( $available_gateways ) {
global $woocommerce;
if ( is_admin() ) return;
if ( isset( $available_gateways['stripe'] ) && $woocommerce->customer->get_billing_country() <> 'US' ) {
unset( $available_gateways['stripe'] );
} 
return $available_gateways;
}
 
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_country' );

If you’re using WooCommerce 2.6 or older:

function payment_gateway_disable_country( $available_gateways ) {
global $woocommerce;
if ( isset( $available_gateways['stripe'] ) && $woocommerce->customer->get_country() <> 'US' ) {
unset( $available_gateways['stripe'] );
} 
return $available_gateways;
}
 
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_country' );

In this example I’m disabling my Stripe credit card payment gateway if the country is not equal to the United States (US).  In doing this anyone outside of the United States (US) when checking out and entering their billing/shipping address will have to pay with my other payment gateway of PayPal.

You can enter any of your gateways here to disable by going into your WordPress admin area -> WooCommerce -> Settings -> Checkout and viewing the gatewayID.

Disable Payment Gateways Based on Country in WooCommerce

You can look up the country code here.  Once you’re ready save your functions.php file and you’re all set.

View the Prodjex Web Development form discussion on how to Disable Payment Gateways Based on Country in WooCommerce.

8 Comments

  • camilo camilo says:

    great method, i use it for billing_state and worked great too

  • Irvin Irvin says:

    how can I add multiple countries in the same code?
    if ( isset( $available_gateways[‘stripe’] ) && $woocommerce->customer->get_billing_country() ‘US’, ‘CA’ ) {

    Like above?

  • jawad jawad says:

    How can I disable payment for specific cities?

    Can you suggest a solution?

  • Fozan Fozan says:

    How to implement this city wise?

  • Ony Ony says:

    This did not work for me:( I am not sure what I am doing wrong.

  • Remitur Remitur says:

    Works fine but, for some kind of unclear reason, does not work for PayPal.
    I.e. this code:
    function payment_gateway_disable_country( $available_gateways ) {
    global $woocommerce;
    if ( is_admin() ) return;
    if ( isset( $available_gateways[‘ppcp_gateway’] ) && $woocommerce->customer->get_billing_country() === ‘IT’ ) {
    unset( $available_gateways[‘ppcp_gateway’] );
    }
    return $available_gateways;
    }
    add_filter( ‘woocommerce_available_payment_gateways’, ‘payment_gateway_disable_country’ );

    does not work. But i.e. substituting ppcp_gateway (PayPal) with cpsw_stripe (Stripe) works fine…

    Any idea why (but for “PayPal sucks”), and how to fix it?

  • pets brand pets brand says:

    How can I disable payment for specific cities?
    I don’t what is reason can somebody explain me

Leave a Reply