Category: Wordpress

Disable Payment Gateway for a Specific Country in WooCommerce

If you want to disable payment gateway for a specific country in WooCommerce then you have to decide the payment gateway and country code. Here I’m disabling the cod for India. You have to replace “cod” instead of your payment gateway. Have to replace “IN” instead of your decided country code. Place the following code in your functions.php file.

function disable_payment_gateway_for_a_country( $available_gateways ) {
  global $woocommerce;
  if ( isset( $available_gateways['cod'] ) && $woocommerce->customer->get_country() == 'IN' ) 
    unset( $available_gateways['cod'] );
  return $available_gateways;
add_filter( 'woocommerce_available_payment_gateways', 'disable_payment_gateway_for_a_country' );

Have any doubt, then comment here!