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.

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.

Here is what we are going to create:

restrict WooCommerce payment gateways by country selected
At the moment of writing this tutorial PayPal doesn’t work for Monaco. So let’s deactivate PayPal payment gateway for Monaco.
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;


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
   // more countries here...

if( in_array( $country, $countries ) ) {
Misha Rudrastyh

Misha Rudrastyh

I develop websites since 2008, so it is total of 13 years of experience, oh my gosh. Most of all I love love love to create websites with WordPress and Gutenberg, some ideas and thoughts I share throughout my blog.

Need some developer help? Contact me

Follow me on Twitter