WC_Countries::get_address_fields PHP Метод

get_address_fields() публичный Метод

Apply locale and get address fields.
public get_address_fields ( mixed $country = '', string $type = 'billing_' ) : array
$country mixed (default: '')
$type string (default: 'billing_')
Результат array
    public function get_address_fields($country = '', $type = 'billing_')
    {
        if (!$country) {
            $country = $this->get_base_country();
        }
        $fields = $this->get_default_address_fields();
        $locale = $this->get_country_locale();
        if (isset($locale[$country])) {
            $fields = wc_array_overlay($fields, $locale[$country]);
        }
        // Prepend field keys
        $address_fields = array();
        foreach ($fields as $key => $value) {
            $keys = array_keys($fields);
            $address_fields[$type . $key] = $value;
        }
        // Add email and phone fields.
        if ('billing_' === $type) {
            $address_fields['billing_phone'] = array('label' => __('Phone', 'woocommerce'), 'required' => true, 'type' => 'tel', 'class' => array('form-row-first'), 'validate' => array('phone'), 'autocomplete' => 'tel');
            $address_fields['billing_email'] = array('label' => __('Email address', 'woocommerce'), 'required' => true, 'clear' => true, 'type' => 'email', 'class' => array('form-row-last'), 'validate' => array('email'), 'autocomplete' => 'no' === get_option('woocommerce_registration_generate_username') ? 'email' : 'email username');
        }
        /**
         * Important note on this filter: Changes to address fields can and will be overridden by
         * the woocommerce_default_address_fields. The locales/default locales apply on top based
         * on country selection. If you want to change things like the required status of an
         * address field, filter woocommerce_default_address_fields instead.
         */
        $address_fields = apply_filters('woocommerce_' . $type . 'fields', $address_fields, $country);
        return $address_fields;
    }

Usage Example

        <th scope="row" class="titledesc"> <label for="apg_sms_settings[campo_envio]">
            <?php 
_e('Shipping mobile field:', 'apg_sms');
?>
          </label>
          <span class="woocommerce-help-tip" data-tip="<?php 
_e('Select the shipping mobile field', 'apg_sms');
?>
"></span> </th>
        <td class="forminp forminp-number"><select id="apg_sms_settings[campo_envio]" name="apg_sms_settings[campo_envio]" class="wc-enhanced-select" tabindex="<?php 
echo $tab++;
?>
">
        <?php 
$pais = new WC_Countries();
$campos = $pais->get_address_fields($pais->get_base_country(), 'shipping_');
//Campos ordinarios
$campos_personalizados = apply_filters('woocommerce_checkout_fields', array());
if (isset($campos_personalizados['shipping'])) {
    $campos += $campos_personalizados['shipping'];
}
foreach ($campos as $valor => $campo) {
    $chequea = isset($configuracion['campo_envio']) && $configuracion['campo_envio'] == $valor ? ' selected="selected"' : '';
    if (isset($campo['label'])) {
        echo '<option value="' . $valor . '"' . $chequea . '>' . $campo['label'] . '</option>' . PHP_EOL;
    }
}
?>
        </select></td>
      </tr>
      <?php 
All Usage Examples Of WC_Countries::get_address_fields