If you’re using WooCommerce and selling primarily to a single country, it’s nice to set a default country on the checkout page shipping drop-down. We recently had a customer ask how to move the United States to the top of the dropdown list. Here’s how you do that.
In either functions.php
, or a functionality plugin, add this code:
/**
* Change the default country on the checkout page
*/
add_filter( 'default_checkout_billing_country', 'change_default_checkout_country' );
function change_default_checkout_country() {
return 'US'; // Put Country code here
}
Which country?
In this case, USA!
What about a default state?
We’ve got you covered there too:
/**
* Change the default state on the checkout page
*/
add_filter( 'default_checkout_billing_country', 'change_default_checkout_country' );
add_filter( 'default_checkout_billing_state', 'change_default_checkout_state' );
function change_default_checkout_state() {
return 'XX'; // state code
}
3 Comments
Thanks for this post, however the code is not visible
Hi Jay,
Well for some reason our Gists aren’t showing. Maybe it’s time to repost these scripts directly. You can see the Gist here: https://gist.github.com/spigotdesign/6d7b44d5ba9d801c6f9a796a3edf79cb
Thank you Bryan You helped me with Shipping country default with this code
/**
* Change the default country on the checkout page
*/
add_filter( ‘default_checkout_shipping_country’, ‘change_default_checkout_country’ );
function change_default_checkout_country() {
return ‘US’; // Put Country code here
}