Change the Default State and Country on the WooCommerce Checkout

Quick Summary
- For new customers, WooCommerce uses the Default customer location setting: Shop country/region starts them in your store's country and state.
- To default to another country in both the Checkout block and the classic checkout, filter woocommerce_customer_default_location and return a code like 'US:NY'.
- The default_checkout_billing_country and _state filters only affect the classic shortcode checkout, and they replace addresses customers have saved.
To change the default country and state on the WooCommerce checkout for new customers, set your store’s country in WooCommerce > Settings > General and choose Shop country/region as the Default customer location. To default to a different country, filter woocommerce_customer_default_location; that works for both the Checkout block and the classic checkout. The older default_checkout_billing_country and default_checkout_billing_state filters only change the classic shortcode checkout, and they replace addresses that customers have saved.
Which checkout does your store use?
WooCommerce has two checkouts, and the code for one doesn’t always apply to the other:
- The Checkout block. According to WooCommerce’s documentation, stores created after WooCommerce 8.3 (November 2023) use the Cart and Checkout blocks by default.
- The classic checkout. The checkout page contains the
[woocommerce_checkout]shortcode, or the Classic Checkout block that wraps it. Older stores usually still use this one.
Open your checkout page in the editor to see which one you have.
Both checkouts start from the address WooCommerce keeps for the customer. A logged-in customer’s saved billing address comes first. For new visitors and customers without a saved address, WooCommerce fills in a default location, and that default is what the settings and the first snippet below change.
Set the default without code
Go to WooCommerce > Settings > General:
- Store Address > Country / State is your shop’s location.
- Default customer location decides what new customers start with. Shop country/region uses the country and state of the store address. Geolocate and Geolocate (with page caching support) look up the visitor’s country from their IP address and fall back to the store address when the lookup finds nothing. No location by default leaves the country empty.
If most of your customers are in the country your store is in, this is all you need.
Set a different default country for both checkouts
When the default should be a country other than your store’s, filter the default customer location. Add this to your child theme’s functions.php file or a custom plugin:
add_filter( 'woocommerce_customer_default_location', 'nmh47_default_customer_location' );
function nmh47_default_customer_location( $location ) {
return 'US:NY'; // Country code, or country code:state code.
}- Return a two-letter country code such as
'DE', or a country and a state separated by a colon, such as'US:NY'for New York. WooCommerce splits the string at the colon. The post on removing states from the checkout dropdown shows where WooCommerce keeps its list of state codes. - The country must be one you sell to (Selling location(s) in the same settings screen). If it isn’t, WooCommerce drops it and the country starts empty.
- It only fills in customers who don’t have a country yet, so a logged-in customer’s saved address still wins. For customers with no shipping address, WooCommerce copies the same country and state to the shipping address.
- The filter runs before geolocation. With Geolocate on, a successful lookup still wins, and your value is the fallback. It also applies when Default customer location is No location by default.
To force the country even when geolocation is on, use woocommerce_customer_default_location_array instead. It runs after geolocation and receives and returns an array:
add_filter( 'woocommerce_customer_default_location_array', 'nmh47_default_customer_location_array' );
function nmh47_default_customer_location_array( $location ) {
return array(
'country' => 'DE',
'state' => '',
);
}WooCommerce keeps the address in the visitor’s session and only fills in the default when the country is empty. Once a country has been saved in a visitor’s session, changing the filter doesn’t affect that visitor, so test in a private browser window.
Change the fields on the classic checkout
On the classic checkout, WooCommerce runs a default_checkout_ filter for every field just before it prints the form, named after the field: default_checkout_billing_country, default_checkout_billing_state, default_checkout_shipping_country and so on. The filter receives the value WooCommerce was about to use (the customer’s saved or default address) and the field name. This snippet sets the country and state for every customer:
/**
* Change the default state and country 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_country() {
return 'US'; // Country code.
}
function change_default_checkout_state() {
return 'NY'; // State code.
}- Replace
'US'with a two-letter country code and'NY'with a state code for that country. - The value you return replaces the address a logged-in customer has saved, so a returning customer from another country has to change it every time.
- These filters don’t affect the Checkout block. The block loads the address through WooCommerce’s Store API and never runs them.
Change the default only for new customers (classic checkout)
If you only want to change the default on the classic checkout for customers who haven’t ordered before, use this version instead. It receives the current value as $country and returns it unchanged when WC()->customer->get_is_paying_customer() is true, meaning the customer has already paid for an order. Everyone else, including guests, gets Germany ('DE') as the default.
/**
* Change the default country on the checkout for non-existing users only
*/
add_filter( 'default_checkout_billing_country', 'change_default_checkout_country', 10, 1 );
function change_default_checkout_country( $country ) {
// If the user already exists, don't override country
if ( WC()->customer->get_is_paying_customer() ) {
return $country;
}
return 'DE'; // Override default to Germany (an example)
}- Replace
'DE'with your own country code. This version doesn’t change the state field. - A registered customer who has never paid for an order still counts as new here, and gets Germany even if they saved another country.
- Both classic snippets declare a function called
change_default_checkout_country(), so use one or the other. Adding both causes a fatal “cannot redeclare” error. - The
woocommerce_customer_default_locationsnippet above does a similar job on both checkouts: it leaves every saved address alone, not only those of paying customers.
Frequently asked questions
Why doesn’t the default change on my checkout?
The usual reasons are that the store uses the Checkout block and the code uses the classic default_checkout_ filters, that the customer is logged in and has a saved address, or that the visitor’s session already holds a country. Geolocation can also override woocommerce_customer_default_location. Clear your page cache and test as a logged-out visitor in a private window.
How do you change the default shipping country?
For customers without a shipping address, WooCommerce copies the billing default to the shipping address, so the default customer location covers both. On the classic checkout, default_checkout_shipping_country and default_checkout_shipping_state set the starting values of the shipping fields in the same way as the billing filters above.
Can you leave the country empty so customers have to choose?
Yes. Set Default customer location to No location by default and don’t add a filter. New customers then start with an empty country, and customers with a saved address still get theirs.
Checkout defaults are a small fix. When the whole checkout needs rework, see my WooCommerce development services.
Related articles
- closing the shipping address fields by default: another checkout default you set with one filter
- showing full country names in the shipping error: for customers who pick a country you don’t ship to
