Skip to content

Instantly share code, notes, and snippets.

@thesadoo
Created November 17, 2016 23:29
Show Gist options
  • Save thesadoo/14385afd36040d4fbd4578970ef4a1f3 to your computer and use it in GitHub Desktop.
Save thesadoo/14385afd36040d4fbd4578970ef4a1f3 to your computer and use it in GitHub Desktop.
WooCommerce set default values in checkout page for shipping/billing fields. I used it to set a default city.
<?php
add_filter( 'woocommerce_checkout_fields' , 'default_values_checkout_fields' );
// You can use this for postcode, address, company, first name, last name and such.
// field names can be found here:
// https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
// found the main function woocommerce_form_field() here:
// https://github.com/woocommerce/woocommerce/blob/76b32c9aa52ebac70fe5a60a8d56351218760471/includes/wc-template-functions.php
function default_values_checkout_fields( $fields ) {
$fields['billing']['billing_city']['default'] = 'SomeCity';
$fields['shipping']['shipping_city']['default'] = 'SomeCity';
return $fields;
}
// and you can just use CSS to hide the inputs, you know.
?>
@lenina33
Copy link

lenina33 commented Nov 30, 2021

Is it possible to set default address only for some shipping methods and for others leave blank fields?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment