get_country_locale() public method

Get country locale settings.
public get_country_locale ( ) : array
return array
Beispiel #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/ajax-loader@2x.gif'), '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);
     }
 }
 /**
  * Register/queue frontend scripts.
  *
  * @access public
  * @return void
  */
 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;
     $frontend_script_path = $this->plugin_url() . '/assets/js/frontend/';
     // Register any scipts for later use, or used as dependencies
     wp_register_script('chosen', $this->plugin_url() . '/assets/js/chosen/chosen.jquery' . $suffix . '.js', array('jquery'), $this->version, true);
     wp_register_script('jquery-ui', $this->plugin_url() . '/assets/js/jquery-ui' . $suffix . '.js', array('jquery'), $this->version, true);
     wp_register_script('jquery-plugins', $this->plugin_url() . '/assets/js/jquery-plugins' . $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);
     // Queue frontend scripts conditionally
     if (get_option('woocommerce_enable_ajax_add_to_cart') == 'yes') {
         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()) {
         wp_enqueue_script('wc-checkout', $frontend_script_path . 'checkout' . $suffix . '.js', array('jquery'), $this->version, true);
     }
     if (is_product()) {
         wp_enqueue_script('wc-single-product');
     }
     if ($lightbox_en && (is_product() || !empty($post->post_content) && strstr($post->post_content, '[product_page'))) {
         wp_enqueue_script('fancybox', $this->plugin_url() . '/assets/js/fancybox/fancybox' . $suffix . '.js', array('jquery'), $this->version, true);
         wp_enqueue_style('woocommerce_fancybox_styles', $this->plugin_url() . '/assets/css/fancybox.css');
     }
     if ($chosen_en && is_checkout()) {
         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');
     }
     // Global frontend scripts
     wp_enqueue_script('woocommerce', $frontend_script_path . 'woocommerce' . $suffix . '.js', array('jquery', 'jquery-plugins'), $this->version, true);
     // Variables for JS scripts
     $woocommerce_params = array('countries' => json_encode($this->countries->get_allowed_country_states()), 'select_state_text' => __('Select an option…', 'woocommerce'), 'plugin_url' => $this->plugin_url(), 'ajax_url' => $this->ajax_url(), 'ajax_loader_url' => apply_filters('woocommerce_ajax_loader_url', $this->plugin_url() . '/assets/images/ajax-loader.gif'), 'required_rating_text' => esc_attr__('Please select a rating', 'woocommerce'), 'review_rating_required' => get_option('woocommerce_review_rating_required'), 'required_text' => esc_attr__('required', 'woocommerce'), '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"), 'add_to_cart_nonce' => wp_create_nonce("add-to-cart"));
     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));
 }
 function init_address_fields($b_country = '', $s_country = '', $show_country = true)
 {
     $this->billing_fields = apply_filters('woocommerce_admin_billing_fields', array('first_name' => array('label' => __('First Name', 'woocommerce'), 'show' => false), 'last_name' => array('label' => __('Last Name', 'woocommerce'), 'show' => false), 'company' => array('label' => __('Company', 'woocommerce'), 'show' => false), 'address_1' => array('label' => __('Address 1', 'woocommerce'), 'show' => false), 'address_2' => array('label' => __('Address 2', 'woocommerce'), 'show' => false), 'city' => array('label' => __('City', 'woocommerce'), 'show' => false), 'postcode' => array('label' => __('Postcode', 'woocommerce'), 'show' => false), 'country' => array('label' => __('Country', 'woocommerce'), 'show' => false, 'class' => 'js_field-country select short', 'type' => 'select', 'options' => array('' => __('Select a country…', 'woocommerce')) + WC()->countries->get_allowed_countries()), 'state' => array('label' => __('State/County', 'woocommerce'), 'class' => 'js_field-state select short', 'show' => false), 'email' => array('label' => __('Email', 'woocommerce')), 'phone' => array('label' => __('Phone', 'woocommerce'))));
     $this->shipping_fields = apply_filters('woocommerce_admin_shipping_fields', array('first_name' => array('label' => __('First Name', 'woocommerce'), 'show' => false), 'last_name' => array('label' => __('Last Name', 'woocommerce'), 'show' => false), 'company' => array('label' => __('Company', 'woocommerce'), 'show' => false), 'address_1' => array('label' => __('Address 1', 'woocommerce'), 'show' => false), 'address_2' => array('label' => __('Address 2', 'woocommerce'), 'show' => false), 'city' => array('label' => __('City', 'woocommerce'), 'show' => false), 'postcode' => array('label' => __('Postcode', 'woocommerce'), 'show' => false), 'country' => array('label' => __('Country', 'woocommerce'), 'show' => false, 'type' => 'select', 'class' => 'js_field-country select short', 'options' => array('' => __('Select a country…', 'woocommerce')) + WC()->countries->get_shipping_countries()), 'state' => array('label' => __('State/County', 'woocommerce'), 'class' => 'js_field-state select short', 'show' => false)));
     if (!empty($b_country) || !empty($s_country)) {
         $countries = new WC_Countries();
         $locale = $countries->get_country_locale();
         $state_arr = WC()->countries->get_allowed_country_states();
     }
     if (!empty($b_country)) {
         if (isset($locale[$b_country])) {
             $this->billing_fields = wc_array_overlay($this->billing_fields, $locale[$b_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[$b_country]['postcode_before_city'])) {
                 if (isset($this->billing_fields['postcode'])) {
                     $this->billing_fields['postcode']['class'] = array('form-row-wide', 'address-field');
                     $switch_fields = array();
                     foreach ($this->billing_fields as $key => $value) {
                         if ($key == 'city') {
                             // Place postcode before city
                             $switch_fields['postcode'] = '';
                         }
                         $switch_fields[$key] = $value;
                     }
                     $this->billing_fields = $switch_fields;
                 }
             }
             if (isset($state_arr[$b_country]) && !empty($state_arr[$b_country])) {
                 $this->billing_fields['state']['type'] = 'select';
                 $this->billing_fields['state']['class'] = array('form-row-left', 'address-field', 'chosen_select');
                 $this->billing_fields['state']['options'] = $state_arr[$b_country];
             }
         }
     }
     if (!empty($s_country)) {
         if (isset($locale[$s_country])) {
             $this->shipping_fields = wc_array_overlay($this->shipping_fields, $locale[$s_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[$s_country]['postcode_before_city'])) {
                 if (isset($this->shipping_fields['postcode'])) {
                     $this->shipping_fields['postcode']['class'] = array('form-row-wide', 'address-field');
                     $switch_fields = array();
                     foreach ($this->shipping_fields as $key => $value) {
                         if ($key == 'city') {
                             // Place postcode before city
                             $switch_fields['postcode'] = '';
                         }
                         $switch_fields[$key] = $value;
                     }
                     $this->shipping_fields = $switch_fields;
                 }
             }
             if (isset($state_arr[$s_country]) && !empty($state_arr[$s_country])) {
                 $this->shipping_fields['state']['type'] = 'select';
                 $this->shipping_fields['state']['class'] = array('form-row-left', 'address-field', 'chosen_select');
                 $this->shipping_fields['state']['options'] = $state_arr[$b_country];
             }
         }
     }
 }