I am selling products to 4 countries; US, Canada, UK and France. I have enabled 2 checkout methods; Cash on Delivery (cod) and Paypal. I want to restrict cod to Canada only and hide from other countries. I have tried the below code but it makes cod disappear from all countries (including Canada).I know i am doing something wrong here, i am not an expert so need ur help. Thanks

    /**
* @snippet       WooCommerce Disable Payment Gateway for a Specific Country
 */

function payment_gateway_disable_country( $available_gateways ) {
global $woocommerce;
if ( isset( $available_gateways['cod'] ) && $woocommerce->customer->get_country() <> 'France' ) {
unset( $available_gateways['cod'] );
} else if ( isset( $available_gateways['cod'] ) && $woocommerce->customer->get_country() == 'France' ) {
unset( $available_gateways['cod'] );
}
return $available_gateways;
}

add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_country' );

Read more here: WordPress: Cash on Delivery restrict to one country only


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: