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
 * @community     https://businessbloomer.com/club/
 */

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 custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Cart and Checkout on the Same Page
    This is your ultimate guide – complete with shortcodes, snippets and workarounds – to completely skip the Cart page and have both cart table and checkout form on the same (Checkout) page. But first… why’d you want to do this? Well, if you sell high ticket products (i.e. on average, you sell no more than […]
  • WooCommerce: Disable Payment Method If Product Category @ Cart
    Today we take a look at the WooCommerce Checkout and specifically at how to disable a payment gateway (e.g. PayPal) if a specific product category is in the Cart. There are two tasks to code in this case: (1) based on all the products in the Cart, calculate the list of product categories in the […]
  • WooCommerce: Add Privacy Policy Checkbox @ Checkout
    Here’s a snippet regarding the checkout page. If you’ve been affected by GDPR, you will know you now need users to give you Privacy Policy consent. Or, you might need customer to acknowledge special shipping requirements for example. So, how do we display an additional tick box on the Checkout page (together with the existing […]
  • WooCommerce: Redirect to Custom Thank you Page
    How can you redirect customers to a beautifully looking, custom, thank you page? Thankfully you can add some PHP code to your functions.php or install a simple plugin and define a redirect to a custom WordPress page (as opposed to the default order-received endpoint). This is a great way for you to add specific up-sells, […]
  • WooCommerce: Disable Payment Gateway by Country
    You might want to disable PayPal for non-local customers or enable a specific gateway for only one country… Either way, this is a very common requirement for all of those who trade internationally. Here’s a simple snippet you can further customize to achieve your objective. Simply pick the payment gateway “slug” you want to disable/enable […]

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

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? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. 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 the Business Bloomer Club to get quick WooCommerce support. Thank you!

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