public
Last active

WooCommerce - Set default state/country for checkout

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/**
* Manipulate default state and countries
*
* As always, code goes in your theme functions.php file
*/
add_filter( 'default_checkout_country', 'change_default_checkout_country' );
add_filter( 'default_checkout_state', 'change_default_checkout_state' );
 
function change_default_checkout_country() {
return 'XX'; // country code
}
 
function change_default_checkout_state() {
return 'XX'; // state code
}

This does't work for me. I'm using this piece of code:

add_filter( 'default_checkout_country', 'mhxl_default_checkout_country' );
function mhxl_default_checkout_country()
{
return 'NL';
}

This doesn't work for me either. Here is the code I'm using:

add_filter( 'default_checkout_country', 'change_default_checkout_country' );

function change_default_checkout_country() {
return 'US'; // country code
}

Please help

Not working here either with:

add_filter( 'default_checkout_country', 'change_default_checkout_country' );

function change_default_checkout_country() {
return 'GB'; //country code
}

Possible solution for those having an issue above. If you are logged into WordPress, WooCommerce will set the default country and state to what is available from your profile. If they are not set, it will ask you to choose one. Either fill out your profile details or logout and you will see the correct default country.

  • Jon

Thanks mattowc. I checked in a different different browser and it was working just fine.

"Possible solution for those having an issue above. If you are logged into WordPress, WooCommerce will set the default country and state to what is available from your profile. If they are not set, it will ask you to choose one. Either fill out your profile details or logout and you will see the correct default country."

I am still having the issue of a logged-in user not having the country auto-populated, even though their profile shows that they have a country selected. Advice?

This does not work for me - people can only get shipped to Washington, state, our base state - are there any caches we/they need to clear? Browsers they can not use, etc.?

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.