Created
October 28, 2015 21:59
-
-
Save ScottDeLuzio/90fd7b11c8e0dba539a0 to your computer and use it in GitHub Desktop.
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
remove_filter( 'woocommerce_default_address_fields', 'get_default_address_fields', 10, 1 ); | |
add_filter( 'woocommerce_default_address_fields', 'updated_get_default_address_fields', 10, 1 ); | |
function updated_get_default_address_fields() { | |
global $woocommerce; | |
$fields = array( | |
'first_name' => array( | |
'label' => __( 'First Name', 'woocommerce' ), | |
'required' => true, | |
'class' => array( 'form-row-first' ), | |
), | |
'last_name' => array( | |
'label' => __( 'Last Name', 'woocommerce' ), | |
'required' => true, | |
'class' => array( 'form-row-last' ), | |
'clear' => true | |
), | |
'company' => array( | |
'label' => __( 'Company Name', 'woocommerce' ), | |
'class' => array( 'form-row-wide' ), | |
), | |
'country' => array( | |
'type' => 'country', | |
'label' => __( 'Country', 'woocommerce' ), | |
'required' => true, | |
'class' => array( 'form-row-wide', 'address-field', 'update_totals_on_change' ), | |
), | |
'address_1' => array( | |
'label' => __( 'Address', 'woocommerce' ), | |
'placeholder' => _x( 'Street address', 'placeholder', 'woocommerce' ), | |
'required' => true, | |
'class' => array( 'form-row-wide', 'address-field' ) | |
), | |
'address_2' => array( | |
'placeholder' => _x( 'Apartment, suite, unit etc. (optional)', 'placeholder', 'woocommerce' ), | |
'class' => array( 'form-row-wide', 'address-field' ), | |
'required' => false | |
), | |
'city' => array( | |
'label' => __( 'Town / City', 'woocommerce' ), | |
'placeholder' => __( 'Town / City', 'woocommerce' ), | |
'required' => true, | |
'class' => array( 'form-row-wide', 'address-field' ) | |
), | |
'state' => array( | |
'type' => 'state', | |
'label' => __( 'State / County', 'woocommerce' ), | |
'required' => true, | |
'class' => array( 'form-row-first', 'address-field' ), | |
'validate' => array( 'state' ) | |
), | |
'postcode' => array( | |
'label' => __( 'Postcode / Zip', 'woocommerce' ), | |
'placeholder' => __( 'Postcode / Zip', 'woocommerce' ), | |
'required' => ($woocommerce->customer->get_country() == 'IE') ? false : true, | |
'class' => array( 'form-row-last', 'address-field' ), | |
'clear' => true, | |
'validate' => array( 'postcode' ) | |
), | |
); | |
return $fields; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Scott,
this works really well, but does not impact the shipping address fields. I have added another section for that plus a few other bits I cobbled from various sources. Any comments appreciated.