Disable Payment Gateway for Specific Country
In this tutorial we are going to talk about country based payments in WooCommerce. Because it is a common case that some payment gateways may not work for specific countries.
In this tutorial I will show you how to condition it easily and without any plugins.
Here is what we are going to create:

But if you need custom coding help with conditioning WooCommerce payment gateways or maybe you need to develop one – please feel free to contact me.
add_filter( 'woocommerce_available_payment_gateways', 'rudr_gateway_by_country' );
function rudr_gateway_by_country( $gateways ) {
if( is_admin() ) {
return $gateways;
}
if( is_wc_endpoint_url( 'order-pay' ) ) { // Pay for order page
$order = wc_get_order( wc_get_order_id_by_order_key( $_GET[ 'key' ] ) );
$country = $order->get_billing_country();
} else { // Cart page
$country = WC()->customer->get_billing_country();
}
if ( 'MC' === $country ) {
if ( isset( $gateways[ 'paypal' ] ) ) {
unset( $gateways[ 'paypal' ] );
}
}
return $gateways;
}
- In order to condition payment methods by country, first of all you have to use
WC()->customer->get_billing_country()
to get a billing country orWC()->customer->get_shipping_country()
to get a shipping country. If you set in WooCommerce shipping options to use your billing address as default shipping destination,WC()->customer->get_shipping_country()
will also return your billing country. - Where to get country code? It is in ISO 3166-1 alpha-2 format, full list you can find in wikipedia.
- Where to get a payment gateway ID? If you are uncomfortable with inspecting code in your browser, I can suggest you to add a column with payment gateway ID in WooCommerce settings.
- Never forget to use
isset( $gateways[ 'paypal' ] )
condition, especially for custom payment gateways. Because if you deactivate a plugin with a custom payment method, you will get a PHP notice. - You shouldn’t forget about “Pay for order” page, that’s why I added a condition
is_wc_endpoint_url( 'order-pay' )
on line 9.
How to Check Multiple Countries
Well, it is quite rare when a payment gateway may not support the only one single country 😈 In many cases you would need to check against multiple countries.
if ( 'MC' === $country || 'MY' === $country ) {
Or even better way
$countries = array( // array of unsupported countries
'MC',
'MY',
// more countries here...
);
if( in_array( $country, $countries ) ) {

Misha Rudrastyh
Hey guys and welcome to my website. For more than 10 years I've been doing my best to share with you some superb WordPress guides and tips for free.
Need some developer help? Contact me
Very useful, thank you.
One question – What if you want to restrict a payment method is the country is not ‘MC’.
Would line 20 be:
if ( 'MC' !== $country ) {
?Yep, you’re right
Hi Misha,
Very useful code and right in the direction I’ve been looking for. But for our webshop we would like a few more restrictions regarding the payments. Can you help me sort it out to adjust the code above for our needs?
Our products only ship within the EU and we’re using 5 payments methods that we would like to restrict:
1. iDeal (only Netherlands)
2. Bancontact (only Belgium)
3. Paypay (All EU countries)
4. Creditcard (All EU countries except Belgium and Netherlands)
5. Sepa transfer (All EU countries except Belgium and Netherlands)
Any suggestion on how to approach this?
Thanks a lot and kind regards,
Mark