WooCommerce: Set Default Billing State / Country @ Checkout

This is a simple PGP snippet that I successfully used on a bunch of websites in order to set the default Billing country or state. This is a great way to save the user some time during checkout (and therefore increase your conversion rate) in case you almost exclusively sell to customers located in a given country or state. Nothing else to say, just… enjoy!

WooCommerce: set the default billing country on the checkout

PHP snippet: Set Default Billing Country or State @ WooCommerce Checkout Page


/**
 * @snippet       Set Default Billing Country @ WooCommerce Checkout Page
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @source        https://businessbloomer.com/?p=601
 * @author        Rodolfo Melogli
 * @compatible    Woo 3.5.4
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

// Example 1: default state to OREGON

add_filter( 'default_checkout_billing_state', 'bbloomer_change_default_checkout_state' );
 
function bbloomer_change_default_checkout_state() {
  return 'OR'; // state code
}

// Example 2: default country to United States

add_filter( 'default_checkout_billing_country', 'bbloomer_change_default_checkout_country' );

function bbloomer_change_default_checkout_country() {
  return 'US'; 
}

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7+.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce Customization?

Check out these free video tutorials!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP

Rodolfo Melogli

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as a 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.

14 thoughts on “WooCommerce: Set Default Billing State / Country @ Checkout

  1. Sorry but just can’t get this to work at all. We have a website where the default country is Sweden, but we need to be able to set the checkout country to another. I used this code ‘as is’ to try and force it to the US, as an example, but the default country is still Sweden. Any ideas?

    1. Hey James, thanks for your comment! Maybe you have geolocation enabled from the WooCommerce settings?

  2. i can set default country if i not go to page chechout.
    Example: i set default country “US” on page cart, and i get billing country on page cart, i not change

    1. Hello Cheng, thanks for your comment. Unfortunately I don’t understand it fully, so maybe you could provide a screenshot? Thank you

  3. Hi, do you how to set default city?

    It’s not working for me. Tried

    
    function default_checkout_city(){
    return 'x'; // state code
    }//add_filter( 'woocommerce_countries_base_city', 'default_checkout_city' );
    
    add_filter( 'woocommerce_countries_base_city' , 'set_woocommerce_countries_base_city' );
    function set_woocommerce_countries_base_city() {
    // Replace with your store town/city
    return 'x';
    }
    
    
    1. Hey there Jhonson, thanks for your comment! See, the city field behaves differently from the state ad country ones: it’s an input text field and not a select box. Today I felt generous though – here’s my brand new post which gives you the solution: https://businessbloomer.com/woocommerce-set-default-city-values-checkout πŸ™‚ Thanks so much!

  4. how to remove the default selected country i need to show ‘select country’, thanks

    1. Hey Satish, thanks for your comment. I think you have something wrong in the WooCommerce settings πŸ™‚ Can you send me a screenshot of your WooCommerce/Settings/General page? Cheers. ~R

      1. thanks Rodolfo,

        I found a solution by in this way,

        add_filter( ‘default_checkout_country’, ‘change_default_checkout_country’ );

        function change_default_checkout_country() {
        return ”;
        }

  5. This is a great snippet, thanks.

    1. Thanks so much for your feedback Debbie!

  6. where about do you insert this code?

    1. Hello Doug, you can do so in your active theme’s function.php file, or use Code Snippets free plugin. Hope this helps!

Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between: [php]code_here[/php]. Failure to complying with this (as well as going off topic) will result in comment deletion. You should expect a reply in about a week - this is a popular blog but I need to get paid work done first. Please consider joining #BloomerArmada to ask me 1-to-1 WooCommerce questions. Thank you :)

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.