Created
November 17, 2016 23:29
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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. | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is it possible to set default address only for some shipping methods and for others leave blank fields?