/**
  * Apply locale and get address fields
  *
  * @access public
  * @param mixed $country
  * @param string $type (default: 'billing_')
  * @return void
  */
 public function get_address_fields($country, $type = 'billing_')
 {
     $fields = $this->get_default_address_fields();
     $locale = $this->get_country_locale();
     if (isset($locale[$country])) {
         $fields = woocommerce_array_overlay($fields, $locale[$country]);
         // If default country has postcode_before_city switch the fields round.
         // This is only done at this point, not if country changes on checkout.
         if (isset($locale[$country]['postcode_before_city'])) {
             if (isset($fields['postcode'])) {
                 $fields['postcode']['class'] = array('form-row-wide', 'address-field');
                 $switch_fields = array();
                 foreach ($fields as $key => $value) {
                     if ($key == 'city') {
                         // Place postcode before city
                         $switch_fields['postcode'] = '';
                     }
                     $switch_fields[$key] = $value;
                 }
                 $fields = $switch_fields;
             }
         }
     }
     // Prepend field keys
     $address_fields = array();
     foreach ($fields as $key => $value) {
         $address_fields[$type . $key] = $value;
     }
     // Billing/Shipping Specific
     if ($type == 'billing_') {
         /*	
         $address_fields['billing_email'] = array(
         	'label' 		=> __( 'Email Address', 'woocommerce' ),
         	'required' 		=> true,
         	'class' 		=> array( 'form-row-first' ),
         	'validate'		=> array( 'email' ),
         );
         $address_fields['billing_phone'] = array(
         	'label' 		=> __( 'Phone', 'woocommerce' ),
         	'required' 		=> true,
         	'class' 		=> array( 'form-row-last' ),
         	'clear'			=> true
         );
         */
         $address_fields = apply_filters('woocommerce_billing_fields', $address_fields, $country);
     } else {
         $address_fields = apply_filters('woocommerce_shipping_fields', $address_fields, $country);
     }
     // Return
     return $address_fields;
 }
/**
 * Merge two arrays
 *
 * @access public
 * @param array $a1
 * @param array $a2
 * @return array
 */
function woocommerce_array_overlay($a1, $a2)
{
    foreach ($a1 as $k => $v) {
        if (!array_key_exists($k, $a2)) {
            continue;
        }
        if (is_array($v) && is_array($a2[$k])) {
            $a1[$k] = woocommerce_array_overlay($v, $a2[$k]);
        } else {
            $a1[$k] = $a2[$k];
        }
    }
    return $a1;
}
 /** Apply locale and get address fields */
 function get_address_fields($country, $type = 'billing_')
 {
     global $woocommerce;
     $locale = $this->get_country_locale();
     $fields = array('first_name' => array('label' => __('First Name', 'woothemes'), 'required' => true, 'class' => array('form-row-first')), 'last_name' => array('label' => __('Last Name', 'woothemes'), 'required' => true, 'class' => array('form-row-last'), 'clear' => true), 'company' => array('label' => __('Company Name', 'woothemes'), 'placeholder' => __('Company (optional)', 'woothemes'), 'clear' => true), 'address_1' => array('label' => __('Address', 'woothemes'), 'required' => true, 'class' => array('form-row-first')), 'address_2' => array('label' => __('Address 2', 'woothemes'), 'placeholder' => __('Address 2 (optional)', 'woothemes'), 'class' => array('form-row-last'), 'label_class' => array('hidden'), 'clear' => true), 'city' => array('label' => __('Town/City', 'woothemes'), 'required' => true, 'class' => array('form-row-first')), 'postcode' => array('label' => __('Postcode/Zip', 'woothemes'), 'required' => true, 'class' => array('form-row-last', 'update_totals_on_change'), 'clear' => true), 'country' => array('type' => 'country', 'label' => __('Country', 'woothemes'), 'required' => true, 'class' => array('form-row-first', 'update_totals_on_change', 'country_select')), 'state' => array('type' => 'state', 'label' => __('State/County', 'woothemes'), 'required' => true, 'class' => array('form-row-last', 'update_totals_on_change'), 'clear' => true));
     if (isset($locale[$country])) {
         $fields = woocommerce_array_overlay($fields, $locale[$country]);
         if (isset($locale[$country]['postcode_before_city'])) {
             $fields['city']['class'] = array('form-row-last');
             $fields['postcode']['class'] = array('form-row-first', 'update_totals_on_change');
         }
     }
     // Prepend field keys
     $address_fields = array();
     foreach ($fields as $key => $value) {
         $address_fields[$type . $key] = $value;
     }
     // Billing/Shipping Specific
     if ($type == 'billing_') {
         $address_fields['billing_email'] = array('label' => __('Email Address', 'woothemes'), 'required' => true, 'class' => array('form-row-first'));
         $address_fields['billing_phone'] = array('label' => __('Phone', 'woothemes'), 'required' => true, 'class' => array('form-row-last'), 'clear' => true);
         $address_fields = apply_filters('woocommerce_billing_fields', $address_fields);
     } else {
         $address_fields = apply_filters('woocommerce_shipping_fields', $address_fields);
     }
     // Return
     return $address_fields;
 }
 /** Apply locale and get address fields */
 function get_address_fields($country, $type = 'billing_')
 {
     $locale = $this->get_country_locale();
     $fields = array('first_name' => array('label' => __('First Name', 'woocommerce'), 'placeholder' => _x('First Name', 'placeholder', 'woocommerce'), 'required' => true, 'class' => array('form-row-first')), 'last_name' => array('label' => __('Last Name', 'woocommerce'), 'placeholder' => _x('Last Name', 'placeholder', 'woocommerce'), 'required' => true, 'class' => array('form-row-last'), 'clear' => true), 'company' => array('label' => __('Company Name (if applicable)', 'woocommerce'), 'placeholder' => _x('Company Name (if applicable)', 'placeholder', 'woocommerce'), 'clear' => true), 'address_1' => array('label' => __('Street Number', 'woocommerce'), 'placeholder' => _x('Street Number', 'placeholder', 'woocommerce'), 'required' => true, 'class' => array('form-row-first')), 'address_2' => array('label' => __('Street Name & Type', 'woocommerce'), 'placeholder' => _x('Street Name & Type', 'placeholder', 'woocommerce'), 'required' => true, 'class' => array('form-row-last'), 'clear' => true), 'city' => array('label' => __('Suburb', 'woocommerce'), 'placeholder' => _x('Suburb', 'placeholder', 'woocommerce'), 'required' => true, 'class' => array('form-row-first')), 'postcode' => array('label' => __('Postcode', 'woocommerce'), 'placeholder' => _x('Postcode', 'placeholder', 'woocommerce'), 'required' => true, 'class' => array('form-row-last', 'update_totals_on_change'), 'clear' => true), 'country' => array('type' => 'country', 'label' => __('Country', 'woocommerce'), 'placeholder' => _x('Country', 'placeholder', 'woocommerce'), 'required' => true, 'class' => array('form-row-first', 'update_totals_on_change', 'country_select')), 'state' => array('type' => 'state', 'label' => __('State/Territory', 'woocommerce'), 'placeholder' => _x('State/Territory', 'placeholder', 'woocommerce'), 'required' => true, 'class' => array('form-row-last', 'update_totals_on_change'), 'clear' => true));
     if (isset($locale[$country])) {
         $fields = woocommerce_array_overlay($fields, $locale[$country]);
         // If default country has postcode_before_city switch the fields round
         if (isset($locale[$country]['postcode_before_city'])) {
             $fields['city']['class'] = array('form-row-last');
             $fields['city']['clear'] = true;
             $fields['postcode']['class'] = array('form-row-first', 'update_totals_on_change');
             $fields['postcode']['clear'] = false;
             $switch_fields = array();
             foreach ($fields as $key => $value) {
                 if ($key == 'city') {
                     // Place postcode before city
                     $switch_fields['postcode'] = '';
                 }
                 $switch_fields[$key] = $value;
             }
             $fields = $switch_fields;
         }
     }
     // Prepend field keys
     $address_fields = array();
     foreach ($fields as $key => $value) {
         $address_fields[$type . $key] = $value;
     }
     // Billing/Shipping Specific
     if ($type == 'billing_') {
         $address_fields['billing_email'] = array('label' => __('Email Address', 'woocommerce'), 'placeholder' => _x('Email Address', 'placeholder', 'woocommerce'), 'required' => true, 'class' => array('form-row-first'));
         $address_fields['billing_phone'] = array('label' => __('Phone Number', 'woocommerce'), 'placeholder' => _x('Phone Number', 'placeholder', 'woocommerce'), 'required' => true, 'class' => array('form-row-last'), 'clear' => true);
         $address_fields = apply_filters('woocommerce_billing_fields', $address_fields);
     } else {
         $address_fields = apply_filters('woocommerce_shipping_fields', $address_fields);
     }
     // Return
     return $address_fields;
 }