Disable Payment Methods for Specific Countries
In this tutorial, we will discuss country-based payments in WooCommerce.
It is a common case that some payment processors work only for customers from specific countries. For example, if you accept payments from customers from Sweden, you’d like to include Klarna payments for them; however, if you also have customers from all over the world, maybe it would be a great idea to hide the Klarna payment method from your WooCommerce store’s checkout page for some countries, right?
Below, I’m going to show you two simple ways of achieving that: at first, we will do it using my Simple Conditional Shipping and Payments plugin, and after that, I will also uncover a programmatic approach, using the woocommerce_available_payment_gateways filter hook.
Sounds good? Let’s dive into it now.
Country-Based Payments for WooCommerce with a Plugin
First of all, let’s take a look at my plugin, which allows you to enable or disable some payment gateways (methods) for selected countries.
Below, in the screenshot, you can see how I configured two conditions with the plugin:
- Only enable the Klarna payment method if a customer’s country is Sweden.
- Only enable the iDEAL payment method if a customer’s country is the Netherlands.
The plugin settings can be found at WooCommerce > Settings > Conditions:

Setting Up Payment Methods by Country Programmatically
It is time to talk about a programmatic approach, and as an example, let’s choose another payment gateway (let’s say, PayPal) and another unsupported country.
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;
}- To condition payment methods by country, first of all, you have to use the
WC()->customer->get_billing_country()method to get the billing country orWC()->customer->get_shipping_country()to get the shipping country of your customer. However, if you selected the “Force shipping to the customer billing address” option in the WooCommerce shipping settings, then theWC()->customer->get_shipping_country()method will also return your billing country. - Where to get the country code? It is in ISO 3166-1 alpha-2 format; the full list can be found in Wikipedia.
- Where to get a payment gateway ID? If you are uncomfortable with inspecting code in your browser, I could suggest adding a column with the 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 the “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 often that a payment processor doesn’t support multiple countries. In that case, it means that we need to slightly modify our condition in the code snippet above, for example:
if ( 'MC' === $country || 'MY' === $country ) {Or an even better way:
$countries = array( // array of unsupported countries
'MC',
'MY',
// more countries here...
);
if( in_array( $country, $countries ) ) {Do you have any questions about the code or the plugin? Feel free to ask in the comments.
Misha Rudrastyh
Hey guys and welcome to my website. For more than 15 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 again,
We’ve been using your code for a few years (without issue), but strangely has recently begun to prevent Elementor JSON files from loading (a 500 error for files like this /wp-json/elementor/v1/global-widget/templates which prevents the Elementor editor from loading).
I can’t see why this is happening, and Elementor won’t help with custom code.
Do you have any idea what could have changed?
It could be either a mod_rewrite, permalinks issue, or maybe authentication with db? I don’t know.
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
Hi Mark,
Currently, you can easily approach this with my plugin.
Just add the 5 conditions you mentioned in the plugin settings, and that’s pretty it.