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

We’ve already seen how to set the default values for certain dropdowns (country and state default: https://businessbloomer.com/woocommerce-set-default-state-checkout-page/). 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: How to Set the Default City @ Checkout

 * @snippet       WooCommerce Set Default City @ Checkout
 * @how-to        Get CustomizeWoo.com FREE
 * @sourcecode    https://businessbloomer.com/?p=21223
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.4.6

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 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. You can start learning how to customize WooCommerce without unnecessary plugins. Watch me code and learn by example!

  • 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.

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

  1. Hi Rodolfo!
    Thanks for this amazing blog.

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

    Thanks a lot!

    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!

  2. 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!

  3. Hi Rodolfo Melogli

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


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

  4. 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

  5. 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


    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

  6. 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: [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 *