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 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
Share:

Leave a Reply