WC_Countries::get_default_address_fields()
Returns the fields we show by default. This can be filtered later on.
Method of the class: WC_Countries{}
Hooks from the method
Return
Array
.
Usage
$WC_Countries = new WC_Countries(); $WC_Countries->get_default_address_fields();
WC_Countries::get_default_address_fields() WC Countries::get default address fields code WC 9.4.2
public function get_default_address_fields() { $address_2_label = __( 'Apartment, suite, unit, etc.', 'woocommerce' ); // If necessary, append '(optional)' to the placeholder: we don't need to worry about the // label, though, as woocommerce_form_field() takes care of that. if ( 'optional' === get_option( 'woocommerce_checkout_address_2_field', 'optional' ) ) { $address_2_placeholder = __( 'Apartment, suite, unit, etc. (optional)', 'woocommerce' ); } else { $address_2_placeholder = $address_2_label; } $fields = array( 'first_name' => array( 'label' => __( 'First name', 'woocommerce' ), 'required' => true, 'class' => array( 'form-row-first' ), 'autocomplete' => 'given-name', 'priority' => 10, ), 'last_name' => array( 'label' => __( 'Last name', 'woocommerce' ), 'required' => true, 'class' => array( 'form-row-last' ), 'autocomplete' => 'family-name', 'priority' => 20, ), 'company' => array( 'label' => __( 'Company name', 'woocommerce' ), 'class' => array( 'form-row-wide' ), 'autocomplete' => 'organization', 'priority' => 30, 'required' => 'required' === get_option( 'woocommerce_checkout_company_field', 'optional' ), ), 'country' => array( 'type' => 'country', 'label' => __( 'Country / Region', 'woocommerce' ), 'required' => true, 'class' => array( 'form-row-wide', 'address-field', 'update_totals_on_change' ), 'autocomplete' => 'country', 'priority' => 40, ), 'address_1' => array( 'label' => __( 'Street address', 'woocommerce' ), /* translators: use local order of street name and house number. */ 'placeholder' => esc_attr__( 'House number and street name', 'woocommerce' ), 'required' => true, 'class' => array( 'form-row-wide', 'address-field' ), 'autocomplete' => 'address-line1', 'priority' => 50, ), 'address_2' => array( 'label' => $address_2_label, 'label_class' => array( 'screen-reader-text' ), 'placeholder' => esc_attr( $address_2_placeholder ), 'class' => array( 'form-row-wide', 'address-field' ), 'autocomplete' => 'address-line2', 'priority' => 60, 'required' => 'required' === get_option( 'woocommerce_checkout_address_2_field', 'optional' ), ), 'city' => array( 'label' => __( 'Town / City', 'woocommerce' ), 'required' => true, 'class' => array( 'form-row-wide', 'address-field' ), 'autocomplete' => 'address-level2', 'priority' => 70, ), 'state' => array( 'type' => 'state', 'label' => __( 'State / County', 'woocommerce' ), 'required' => true, 'class' => array( 'form-row-wide', 'address-field' ), 'validate' => array( 'state' ), 'autocomplete' => 'address-level1', 'priority' => 80, ), 'postcode' => array( 'label' => __( 'Postcode / ZIP', 'woocommerce' ), 'required' => true, 'class' => array( 'form-row-wide', 'address-field' ), 'validate' => array( 'postcode' ), 'autocomplete' => 'postal-code', 'priority' => 90, ), ); if ( 'hidden' === get_option( 'woocommerce_checkout_company_field', 'optional' ) ) { unset( $fields['company'] ); } if ( 'hidden' === get_option( 'woocommerce_checkout_address_2_field', 'optional' ) ) { unset( $fields['address_2'] ); } $default_address_fields = apply_filters( 'woocommerce_default_address_fields', $fields ); // Sort each of the fields based on priority. uasort( $default_address_fields, 'wc_checkout_fields_uasort_comparison' ); return $default_address_fields; }