Skip to content

Instantly share code, notes, and snippets.

@odessy
Last active November 29, 2018 14:51
Show Gist options
  • Save odessy/951eb022f817b8b5928334e754518f2e to your computer and use it in GitHub Desktop.
Save odessy/951eb022f817b8b5928334e754518f2e to your computer and use it in GitHub Desktop.
add address_field_2 in correct location
<?php
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields', 9999 );
function custom_override_checkout_fields( $fields ) {
$address_2 = array(
'placeholder' => __('Appartment, suite, unit etc.(optional)', 'woocommerce'),
'label' => __('Appartment, suite, unit etc.', 'woocommerce'),
'class' => array('form-row-wide', 'address-field'),
'required' => false,
'autocomplete' => "address-line2",
'priority' => 60
);
$new_fields = array();
/*billing fields*/
foreach( $fields['billing'] as $key => $value){
$new_fields[$key] = $value;
if($key == 'billing_address_1'){
$new_fields['billing_address_2'] = $address_2;
}
}
$fields['billing'] = $new_fields;
$new_fields = array();
/*shipping fields*/
foreach( $fields['shipping'] as $key => $value){
$new_fields[$key] = $value;
if($key == 'shipping_address_1'){
$new_fields['shipping_address_2'] = $address_2;
}
}
$fields['shipping'] = $new_fields;
return $fields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment