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
PHP snippet: How to Set the Default City @ Checkout
/**
* @snippet WooCommerce Set Default City @ Checkout
* @how-to Get tutoraspire.com FREE
* @sourcecode https://tutoraspire.com/?p=21223
* @author Tutor Aspire
* @testedwith WooCommerce 3.4.6
*/
add_filter( 'woocommerce_checkout_fields', 'tutoraspire_set_checkout_field_input_value_default' );
function tutoraspire_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: