WC_Countries::get_country_locale PHP Метод

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

Get country locale settings.
public get_country_locale ( ) : array
Результат array
    public function get_country_locale()
    {
        if (empty($this->locale)) {
            // Locale information used by the checkout
            $this->locale = apply_filters('woocommerce_get_country_locale', array('AE' => array('postcode' => array('required' => false, 'hidden' => true)), 'AF' => array('state' => array('required' => false)), 'AT' => array('postcode_before_city' => true, 'state' => array('required' => false)), 'AU' => array('city' => array('label' => __('Suburb', 'woocommerce')), 'postcode' => array('label' => __('Postcode', 'woocommerce')), 'state' => array('label' => __('State', 'woocommerce'))), 'AX' => array('postcode_before_city' => true, 'state' => array('required' => false)), 'BD' => array('postcode' => array('required' => false), 'state' => array('label' => __('District', 'woocommerce'))), 'BE' => array('postcode_before_city' => true, 'state' => array('required' => false, 'label' => __('Province', 'woocommerce'))), 'BI' => array('state' => array('required' => false)), 'BO' => array('postcode' => array('required' => false, 'hidden' => true)), 'BS' => array('postcode' => array('required' => false, 'hidden' => true)), 'CA' => array('state' => array('label' => __('Province', 'woocommerce'))), 'CH' => array('postcode_before_city' => true, 'state' => array('label' => __('Canton', 'woocommerce'), 'required' => false)), 'CL' => array('city' => array('required' => true), 'postcode' => array('required' => false), 'state' => array('label' => __('Region', 'woocommerce'))), 'CN' => array('state' => array('label' => __('Province', 'woocommerce'))), 'CO' => array('postcode' => array('required' => false)), 'CZ' => array('state' => array('required' => false)), 'DE' => array('postcode_before_city' => true, 'state' => array('required' => false)), 'DK' => array('postcode_before_city' => true, 'state' => array('required' => false)), 'EE' => array('postcode_before_city' => true, 'state' => array('required' => false)), 'FI' => array('postcode_before_city' => true, 'state' => array('required' => false)), 'FR' => array('postcode_before_city' => true, 'state' => array('required' => false)), 'HK' => array('postcode' => array('required' => false), 'city' => array('label' => __('Town / District', 'woocommerce')), 'state' => array('label' => __('Region', 'woocommerce'))), 'HU' => array('state' => array('label' => __('County', 'woocommerce'))), 'ID' => array('state' => array('label' => __('Province', 'woocommerce'))), 'IE' => array('postcode' => array('required' => false, 'label' => __('Eircode', 'woocommerce')), 'state' => array('label' => __('County', 'woocommerce'))), 'IS' => array('postcode_before_city' => true, 'state' => array('required' => false)), 'IL' => array('postcode_before_city' => true, 'state' => array('required' => false)), 'IT' => array('postcode_before_city' => true, 'state' => array('required' => true, 'label' => __('Province', 'woocommerce'))), 'JP' => array('state' => array('label' => __('Prefecture', 'woocommerce'))), 'KR' => array('state' => array('required' => false)), 'NL' => array('postcode_before_city' => true, 'state' => array('required' => false, 'label' => __('Province', 'woocommerce'))), 'NZ' => array('postcode' => array('label' => __('Postcode', 'woocommerce')), 'state' => array('required' => false, 'label' => __('Region', 'woocommerce'))), 'NO' => array('postcode_before_city' => true, 'state' => array('required' => false)), 'NP' => array('state' => array('label' => __('State / Zone', 'woocommerce')), 'postcode' => array('required' => false)), 'PL' => array('postcode_before_city' => true, 'state' => array('required' => false)), 'PT' => array('state' => array('required' => false)), 'RO' => array('state' => array('required' => false)), 'SG' => array('state' => array('required' => false)), 'SK' => array('postcode_before_city' => true, 'state' => array('required' => false)), 'SI' => array('postcode_before_city' => true, 'state' => array('required' => false)), 'ES' => array('postcode_before_city' => true, 'state' => array('label' => __('Province', 'woocommerce'))), 'LI' => array('postcode_before_city' => true, 'state' => array('label' => __('Municipality', 'woocommerce'), 'required' => false)), 'LK' => array('state' => array('required' => false)), 'SE' => array('postcode_before_city' => true, 'state' => array('required' => false)), 'TR' => array('postcode_before_city' => true, 'state' => array('label' => __('Province', 'woocommerce'))), 'US' => array('postcode' => array('label' => __('ZIP', 'woocommerce')), 'state' => array('label' => __('State', 'woocommerce'))), 'GB' => array('postcode' => array('label' => __('Postcode', 'woocommerce')), 'state' => array('label' => __('County', 'woocommerce'), 'required' => false)), 'VN' => array('postcode_before_city' => true, 'state' => array('required' => false), 'postcode' => array('required' => false, 'hidden' => false), 'address_2' => array('required' => false, 'hidden' => true)), 'WS' => array('postcode' => array('required' => false, 'hidden' => true)), 'ZA' => array('state' => array('label' => __('Province', 'woocommerce'))), 'ZW' => array('postcode' => array('required' => false, 'hidden' => true))));
            $this->locale = array_intersect_key($this->locale, array_merge($this->get_allowed_countries(), $this->get_shipping_countries()));
            // Default Locale Can be filtered to override fields in get_address_fields().
            // Countries with no specific locale will use default.
            $this->locale['default'] = apply_filters('woocommerce_get_country_locale_default', $this->get_default_address_fields());
            // Filter default AND shop base locales to allow overides via a single function. These will be used when changing countries on the checkout
            if (!isset($this->locale[$this->get_base_country()])) {
                $this->locale[$this->get_base_country()] = $this->locale['default'];
            }
            $this->locale['default'] = apply_filters('woocommerce_get_country_locale_base', $this->locale['default']);
            $this->locale[$this->get_base_country()] = apply_filters('woocommerce_get_country_locale_base', $this->locale[$this->get_base_country()]);
        }
        return $this->locale;
    }

Usage Example

Пример #1
0
 /**
  * Register/queue frontend scripts.
  *
  * @access public
  * @return void
  */
 public function frontend_scripts()
 {
     global $post;
     $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
     $lightbox_en = get_option('woocommerce_enable_lightbox') == 'yes' ? true : false;
     $chosen_en = get_option('woocommerce_enable_chosen') == 'yes' ? true : false;
     $ajax_cart_en = get_option('woocommerce_enable_ajax_add_to_cart') == 'yes' ? true : false;
     $frontend_script_path = $this->plugin_url() . '/assets/js/frontend/';
     // Register any scripts for later use, or used as dependencies
     wp_register_script('chosen', $this->plugin_url() . '/assets/js/chosen/chosen.jquery' . $suffix . '.js', array('jquery'), '0.9.11', true);
     wp_register_script('jquery-blockui', $this->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array('jquery'), '2.60', true);
     wp_register_script('jquery-placeholder', $this->plugin_url() . '/assets/js/jquery-placeholder/jquery.placeholder' . $suffix . '.js', array('jquery'), $this->version, true);
     wp_register_script('wc-add-to-cart-variation', $frontend_script_path . 'add-to-cart-variation' . $suffix . '.js', array('jquery'), $this->version, true);
     wp_register_script('wc-single-product', $frontend_script_path . 'single-product' . $suffix . '.js', array('jquery'), $this->version, true);
     wp_register_script('jquery-cookie', $this->plugin_url() . '/assets/js/jquery-cookie/jquery.cookie' . $suffix . '.js', array('jquery'), '1.3.1', true);
     // Queue frontend scripts conditionally
     if ($ajax_cart_en) {
         wp_enqueue_script('wc-add-to-cart', $frontend_script_path . 'add-to-cart' . $suffix . '.js', array('jquery'), $this->version, true);
     }
     if (is_cart()) {
         wp_enqueue_script('wc-cart', $frontend_script_path . 'cart' . $suffix . '.js', array('jquery'), $this->version, true);
     }
     if (is_checkout()) {
         if ($chosen_en) {
             wp_enqueue_script('wc-chosen', $frontend_script_path . 'chosen-frontend' . $suffix . '.js', array('chosen'), $this->version, true);
             wp_enqueue_style('woocommerce_chosen_styles', $this->plugin_url() . '/assets/css/chosen.css');
         }
         wp_enqueue_script('wc-checkout', $frontend_script_path . 'checkout' . $suffix . '.js', array('jquery', 'woocommerce'), $this->version, true);
     }
     if ($lightbox_en && (is_product() || !empty($post->post_content) && strstr($post->post_content, '[product_page'))) {
         wp_enqueue_script('prettyPhoto', $this->plugin_url() . '/assets/js/prettyPhoto/jquery.prettyPhoto' . $suffix . '.js', array('jquery'), '3.1.5', true);
         wp_enqueue_script('prettyPhoto-init', $this->plugin_url() . '/assets/js/prettyPhoto/jquery.prettyPhoto.init' . $suffix . '.js', array('jquery'), $this->version, true);
         wp_enqueue_style('woocommerce_prettyPhoto_css', $this->plugin_url() . '/assets/css/prettyPhoto.css');
     }
     if (is_product()) {
         wp_enqueue_script('wc-single-product');
     }
     // Global frontend scripts
     wp_enqueue_script('woocommerce', $frontend_script_path . 'woocommerce' . $suffix . '.js', array('jquery', 'jquery-blockui'), $this->version, true);
     wp_enqueue_script('wc-cart-fragments', $frontend_script_path . 'cart-fragments' . $suffix . '.js', array('jquery', 'jquery-cookie'), $this->version, true);
     wp_enqueue_script('jquery-placeholder');
     // Variables for JS scripts
     $woocommerce_params = array('countries' => json_encode($this->countries->get_allowed_country_states()), 'plugin_url' => $this->plugin_url(), 'ajax_url' => $this->ajax_url(), 'ajax_loader_url' => apply_filters('woocommerce_ajax_loader_url', $this->plugin_url() . '/assets/images/[email protected]'), 'i18n_select_state_text' => esc_attr__('Select an option…', 'woocommerce'), 'i18n_required_rating_text' => esc_attr__('Please select a rating', 'woocommerce'), 'i18n_no_matching_variations_text' => esc_attr__('Sorry, no products matched your selection. Please choose a different combination.', 'woocommerce'), 'i18n_required_text' => esc_attr__('required', 'woocommerce'), 'i18n_view_cart' => esc_attr__('View Cart →', 'woocommerce'), 'review_rating_required' => get_option('woocommerce_review_rating_required'), 'update_order_review_nonce' => wp_create_nonce("update-order-review"), 'apply_coupon_nonce' => wp_create_nonce("apply-coupon"), 'option_guest_checkout' => get_option('woocommerce_enable_guest_checkout'), 'checkout_url' => add_query_arg('action', 'woocommerce-checkout', $this->ajax_url()), 'is_checkout' => is_page(woocommerce_get_page_id('checkout')) ? 1 : 0, 'update_shipping_method_nonce' => wp_create_nonce("update-shipping-method"), 'cart_url' => get_permalink(woocommerce_get_page_id('cart')), 'cart_redirect_after_add' => get_option('woocommerce_cart_redirect_after_add'));
     if (is_checkout() || is_cart()) {
         $woocommerce_params['locale'] = json_encode($this->countries->get_country_locale());
     }
     wp_localize_script('woocommerce', 'woocommerce_params', apply_filters('woocommerce_params', $woocommerce_params));
     // CSS Styles
     if (!defined('WOOCOMMERCE_USE_CSS')) {
         define('WOOCOMMERCE_USE_CSS', get_option('woocommerce_frontend_css') == 'yes' ? true : false);
     }
     if (WOOCOMMERCE_USE_CSS) {
         $css = file_exists(get_stylesheet_directory() . '/woocommerce/style.css') ? get_stylesheet_directory_uri() . '/woocommerce/style.css' : $this->plugin_url() . '/assets/css/woocommerce.css';
         wp_enqueue_style('woocommerce_frontend_styles', $css);
     }
 }
All Usage Examples Of WC_Countries::get_country_locale