Set the Default Country on WooCommerce Checkout

Out of the box, WooCommerce’s checkout country dropdown either shows whatever country WooCommerce geolocates from the customer’s IP, or defaults to the store’s base country if geolocation is off. Neither is right for every store. If 95% of your customers are in one country and the geolocation guess is wrong (it often is on cached sites, CDNs, or mobile networks), customers have to scroll a country list of 200+ entries to fix it. That friction costs conversions.

WooCommerce exposes two filters for this: default_checkout_billing_country for the billing form and default_checkout_shipping_country for shipping. Return the ISO country code you want, and that’s the value the dropdown loads with. Customers can still change it; you’re just setting the default.

/**
 * Set the default country on the WooCommerce checkout page.
 *
 * Use the two-letter ISO 3166-1 alpha-2 country code
 * (US, CA, GB, AU, DE, FR, IN, BR, etc).
 */
add_filter('default_checkout_billing_country', 'carticy_default_checkout_country');
add_filter('default_checkout_shipping_country', 'carticy_default_checkout_country');
function carticy_default_checkout_country()
{
    return 'US';
}

Hooking both filters keeps the billing and shipping defaults consistent. If you only want to set one, remove the matching add_filter() line. Common codes: US United States, CA Canada, GB United Kingdom, AU Australia, DE Germany, FR France, IN India, BR Brazil. The full list is the standard ISO 3166-1 alpha-2 set.

Set Country AND State Together

If most of your customers are in one state or province, you can also pre-fill the state dropdown. The state filter expects the state code (two-letter US state, three-letter Canadian province, etc.) and only triggers when the billing country matches your default.

/**
 * Pre-fill default country AND state on the WooCommerce checkout.
 */
add_filter('default_checkout_billing_country', function () {
    return 'US';
});

add_filter('default_checkout_billing_state', function () {
    return 'CA';  // California
});

add_filter('default_checkout_shipping_country', function () {
    return 'US';
});

add_filter('default_checkout_shipping_state', function () {
    return 'CA';
});

Geolocation Conflicts

If WooCommerce geolocation is enabled (WooCommerce > Settings > General > Default customer location), it may override your filter. Geolocation runs before the default filters and supplies its own country guess. Two options: turn geolocation off, or change the setting to “Shop base address” which makes WooCommerce respect the filter values you’ve set. The “Geolocate (with page caching support)” option works around CDN caching but is slower and still occasionally guesses wrong.

For stores with a clearly dominant customer market, hardcoding the country via this snippet is often more reliable than IP-based detection. The 5% of customers from elsewhere have to change the dropdown once; the 95% never have to think about it.

Verification

  1. Add the snippet to your child theme’s functions.php or a custom plugin
  2. Open the checkout page in an incognito window (logged out, fresh session)
  3. Confirm the country dropdown is pre-selected to the country code you set
  4. Confirm the state dropdown is pre-selected (if you used the state filter)
  5. Change the country manually and confirm the form still lets you submit normally

Need Help?

Learn how to add custom code to WordPress or reach out for custom development help.


About the Author

Ali Khallad

Ali Khallad

I’m Ali Khallad, a WordPress developer who’s been building custom plugins and WooCommerce solutions for over 10 years. I created Mega Forms and several extensions you’ll find on Carticy. I love solving tricky WordPress problems and sharing what I learn along the way. When I’m not coding, you’ll find me travelling, riding horses, or hunting down the best local food wherever I am.


More Code Snippets