If you want to disable payment gateway for a specific country in WooCommerce then you have to decide the payment gateway and country code.
payment gateway ID are here in WooCommerce : Wp-admin->Woocommerce->Settings->Checkout
So, here is code. which you can add in your theme’s functions.php file of your active child theme (or theme).Save file and testing in your checkout page!
In the first “if” statement, I decided to unset the payment “cod” outside Australia. What you need to do is inputting the payment name here:
if ( isset( $available_gateways[‘cod’] )
unset( $available_gateways[‘cod’] );
and the country code here:
&& $woocommerce->customer->get_country() <> ‘AU’
in the “else if” statement, I decided to disable “bacs” if the country is Australia.
function payment_gateway_disable_country( $available_gateways ) { global $woocommerce; if ( isset( $available_gateways['cod'] ) && $woocommerce->customer->get_country() <> 'AU' ) { unset( $available_gateways['cod'] ); } else if ( isset( $available_gateways['bacs'] ) && $woocommerce->customer->get_country() == 'AU' ) { unset( $available_gateways['bacs'] ); } return $available_gateways; } add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_country' );
save your functions.php and do a bit of testing in your checkout page!