How to Set the Default Country to USA in WooCommerce Checkout

In a recent Business Bloomer Club Slack thread, a member asked how to set the default country to the United States on the WooCommerce checkout page.

By default, WooCommerce may set the country field to a different option, depending on settings or user location, but it’s possible to customize this to ensure the United States (or any other country) appears as the default in both the billing and shipping fields.

Here’s a quick guide on how to adjust the default billing and shipping country fields to streamline the checkout experience for US-based customers.

Setting the Default Billing Country

To set the default billing country, you can use the default_checkout_billing_country filter. This filter allows you to specify a default country by returning the country’s two-letter code. Here’s how to set it to the United States:

add_filter( 'default_checkout_billing_country', 'change_default_checkout_country' );
function change_default_checkout_country() {
    return 'US'; // 'US' is the two-letter country code for the United States
}

With this code in place, the checkout page will automatically select the United States as the billing country when the page loads, making it faster for customers based in the US.

Setting the Default Shipping Country

To set the default shipping country to the United States, you can use a similar filter called default_checkout_shipping_country. This filter works just like the billing country filter, specifying a default country for shipping:

add_filter( 'default_checkout_shipping_country', 'change_default_checkout_ship_country' );
function change_default_checkout_ship_country() {
    return 'US'; // Set the default shipping country to the United States
}

Using these two filters together ensures that both the billing and shipping country fields default to the United States, which can be particularly useful for stores with a primarily US-based customer base.

Full Code for Setting Both Fields

For convenience, here’s the combined code to set both the billing and shipping country fields to the United States:

// Set default billing country to the United States
add_filter( 'default_checkout_billing_country', 'change_default_checkout_country' );
function change_default_checkout_country() {
    return 'US';
}

// Set default shipping country to the United States
add_filter( 'default_checkout_shipping_country', 'change_default_checkout_ship_country' );
function change_default_checkout_ship_country() {
    return 'US';
}

Conclusion

With these simple filters, WooCommerce can automatically set the United States as the default country for both billing and shipping on the checkout page, saving time for US customers and providing a smoother checkout experience. This approach can also be adapted for other countries by replacing 'US' with the relevant two-letter country code.

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Reply

Your email address will not be published. Required fields are marked *