WooCommerce: Set Default Billing City (or other fields) @ Checkout

We’ve already seen how to set the default values for certain dropdowns (billing country and state, precisely). But what can we do when we want to define the defaults for the other “text” inputs, such as the billing_city?

WooCommerce: set the default billing_city @ checkout
WooCommerce: set the default billing_city @ checkout

PHP Snippet: Set the Default Billing City @ WooCommerce Checkout

/**
 * @snippet       WooCommerce Set Default City @ Checkout
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 7
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_filter( 'woocommerce_checkout_fields', 'bbloomer_set_checkout_field_input_value_default' );

function bbloomer_set_checkout_field_input_value_default($fields) {
    $fields['billing']['billing_city']['default'] = 'London';
    return $fields;
}

How to Set the Default Value for Other WooCommerce Checkout Fields

Of course you can set the default for many more fields, just use the following instead of “[‘billing_city’]” inside the snippet:

  • billing_first_name
  • billing_last_name
  • billing_company
  • billing_address_1
  • billing_address_2
  • billing_city
  • billing_postcode
  • billing_country
  • billing_state
  • billing_email
  • billing_phone
  • shipping_first_name
  • shipping_last_name
  • shipping_company
  • shipping_address_1
  • shipping_address_2
  • shipping_city
  • shipping_postcode
  • shipping_country
  • shipping_state

Where to add custom code?

You should place PHP snippets at the bottom of your child theme functions.php file and CSS at the bottom of its 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 guide "Should I Add Custom Code Via WP Editor, FTP or Code Snippets?" and my video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything went 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.

If you think this code saved you time & money, feel free to join 17,000+ WooCommerce Weekly subscribers for blog post updates and 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance!

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

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.

14 thoughts on “WooCommerce: Set Default Billing City (or other fields) @ Checkout

  1. como integro dentro de esos campos una variables que obtengo de una consulta proveniente de una base de datos?.

    1. Hey Francisco, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  2. Hi Rodolfo!
    Thanks for this amazing blog.

    Question:
    How do I set a default city with no option to change it? (I want it to be “read only”)

    Thanks a lot!
    Shmuel.

    1. Hi Samuel, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  3. I want an automated email regarding city selection in the cart by user to the specified person for that city.
    Can you help it?

    1. Wajid, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  4. Hi Rodolfo Melogli

    how can I add city and country to the United Arab Emirates ?
    I can not add anything !
    I need video tutorials

    https://s8.picofile.com/file/8338374084/United_Arab_Emirates.png

    1. Hey Abdul, thanks for your comment ๐Ÿ™‚ Did you use my snippet?

  5. Awesome.

    How about setting default product data fields for virtual and downloadable products checkbox?

    Any snippets or point in the right direction, thanks.

    1. Hello Sam – thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  6. Dear Rodolfo,
    Many thanks for your good tip. I have a problem about your article that I want to explain your in detail.
    I want to re-order and also remove some fields in checkout page. At first, I used from woo checkout manager and also yith plugin to do that. They had strange problem: when I removed some fields, in checkout page, I got this error: “please enter an address to continue…” I had searched for that and finally I understood that when I removed billing_country field, it causes to error (because behind the scene it didn’t fill out). So I tried to set default value for country and then remove it by codes (or also plugin) but when I have used codes that you have mentioned above, in checkout page, billing_country fields remove and everything works to do checkout process but I have extra field that shows abbreviation of country name. This code in above that you explain it, defines default country but it didn’t have correct showing when you want to remove billing_country.
    I appreciate if you revise this code.

    Many thanks for your good article

    BR
    Mehdi

    1. Mehdi, thanks so much for your comment! Unfortunately this is custom troubleshooting work and I cannot help here via the blog comments. Thanks a lot for your understanding! ~R

  7. Cool tip, it works.
    I’ve got a question, If I want to have dropdown options of cities (like state/county) in place of text field, how do I do that ?

    1. Thank you Abhi! I suggest you change the text field into a select box by looking at this useful blog from WooCommerce itself: https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/. Let me know!

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

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

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