How to change the default address fields in woocommerce checkout.
- by admin
- 0
To alter all billing and shipping fields while checkout.
EG:
add_filter( ‘woocommerce_default_address_fields’, ‘my_default_address_fields’ );
function my_default_address_fields( $fields ) {
//move these around in the order you’d like
$fields2[‘first_name’] = $fields[‘first_name’];
$fields2[‘last_name’] = $fields[‘last_name’];
$fields2[‘phone’] = $fields[‘phone’];
$fields2[’email’] = $fields[’email’];
$fields2[‘company’] = $fields[‘company’];
$fields2[‘address_1’] = $fields[‘address_1’];
$fields2[‘address_2’] = $fields[‘address_2’];
$fields2[‘postcode’] = $fields[‘postcode’];
$fields2[‘city’] = $fields[‘city’];
$fields2[‘city’][‘label’] = ‘City’;
$fields2[‘city’][‘placeholder’] = ‘City’;
$fields2[‘state’] = $fields[‘state’];
$fields2[‘state’][‘label’] = ‘State’;
$fields2[‘country’] = $fields[‘country’];
return $fields2;
}
Details:
To alter all billing and shipping fields while checkout. EG: add_filter( ‘woocommerce_default_address_fields’, ‘my_default_address_fields’ ); function my_default_address_fields( $fields ) { //move these around in the order you’d like $fields2[‘first_name’] = $fields[‘first_name’]; $fields2[‘last_name’] = $fields[‘last_name’]; $fields2[‘phone’] = $fields[‘phone’]; $fields2[’email’] = $fields[’email’]; $fields2[‘company’] = $fields[‘company’]; $fields2[‘address_1’] = $fields[‘address_1’]; $fields2[‘address_2’] = $fields[‘address_2’]; $fields2[‘postcode’] = $fields[‘postcode’]; $fields2[‘city’] = $fields[‘city’]; $fields2[‘city’][‘label’]…
To alter all billing and shipping fields while checkout. EG: add_filter( ‘woocommerce_default_address_fields’, ‘my_default_address_fields’ ); function my_default_address_fields( $fields ) { //move these around in the order you’d like $fields2[‘first_name’] = $fields[‘first_name’]; $fields2[‘last_name’] = $fields[‘last_name’]; $fields2[‘phone’] = $fields[‘phone’]; $fields2[’email’] = $fields[’email’]; $fields2[‘company’] = $fields[‘company’]; $fields2[‘address_1’] = $fields[‘address_1’]; $fields2[‘address_2’] = $fields[‘address_2’]; $fields2[‘postcode’] = $fields[‘postcode’]; $fields2[‘city’] = $fields[‘city’]; $fields2[‘city’][‘label’]…