Sonia Khan Sonia Khan - 5 months ago 18
PHP Question

WooCommerce: Set country by default in checkout page

I am using WooCommerce in my Wordpress web site. The customers billing and shipping details are populated by default on checkout page. I want that the country will not be set by default. Instead it will asked to select country even if user is logged in.

Screenshot link

Any suggestions? What I should do in order to achieve this?

Answer

This are the woocommerce hooks for this purpose (see in here). I am not sure, but you could try this (untested):

/** 
 * Manipulate default state and countries
 */
add_filter( 'default_checkout_country', 'change_default_checkout_country' );
add_filter( 'default_checkout_state', 'change_default_checkout_state' );
function change_default_checkout_country() {
  return null;
}
function change_default_checkout_state() {
  return null;
}

You have to paste that code in the function.php file of your active child theme or theme…
I have replaced the country code 'xx' by null