当前位置: 首页>>代码示例>>PHP>>正文


PHP WC_Geolocation::geolocate_ip方法代码示例

本文整理汇总了PHP中WC_Geolocation::geolocate_ip方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Geolocation::geolocate_ip方法的具体用法?PHP WC_Geolocation::geolocate_ip怎么用?PHP WC_Geolocation::geolocate_ip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WC_Geolocation的用法示例。


在下文中一共展示了WC_Geolocation::geolocate_ip方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: wskl_country_ip_block

 public static function wskl_country_ip_block()
 {
     // 옵션을 업데이트할 때 발생하는 값을 체크하여,
     // DB 덤프 등으로 옮겨 놓은 직후 임시 상태의 사이트에 대해서 IP 블록을 생략.
     $target = wskl_get_option('ip_block_target');
     if (site_url() != $target) {
         return;
     }
     // result sample: array( 'country' => KR, 'state' => '' );
     $result = WC_Geolocation::geolocate_ip($_SERVER['REMOTE_ADDR']);
     $white_list = preg_replace('/\\s+/', '', get_option('wskl_white_ipcode_list'));
     // not a valid white list. ip block will be disabled.
     if (empty($white_list)) {
         return;
     }
     // at least open for wp-login,
     $white_list = explode(',', $white_list);
     $allowed = FALSE;
     foreach ($white_list as $country_code) {
         if ($country_code == $result['country']) {
             $allowed = TRUE;
             break;
         }
     }
     if (!$allowed) {
         wp_die('Blocked by IP');
     }
 }
开发者ID:EricKim65,项目名称:woosym-korean-localization,代码行数:28,代码来源:class-wskl-ip-block.php

示例2: product_by_country

 /**
  * product_by_country.
  *
  * @version 2.5.0
  * @since   2.5.0
  */
 function product_by_country($visible, $product_id)
 {
     // Get the country by IP
     $location = WC_Geolocation::geolocate_ip();
     // Base fallback
     if (empty($location['country'])) {
         $location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', get_option('woocommerce_default_country')));
     }
     $country = isset($location['country']) ? $location['country'] : '';
     $visible_countries = get_post_meta($product_id, '_' . 'wcj_product_by_country_visible', true);
     if (is_array($visible_countries) && !in_array($country, $visible_countries)) {
         return false;
     }
     return $visible;
 }
开发者ID:algoritmika,项目名称:woocommerce-jetpack,代码行数:21,代码来源:class-wcj-product-by-country.php

示例3: wc_setup_locale

    /**
     * Locale settings
     */
    public function wc_setup_locale()
    {
        $user_location = WC_Geolocation::geolocate_ip();
        $country = !empty($user_location['country']) ? $user_location['country'] : 'US';
        $state = !empty($user_location['state']) ? $user_location['state'] : '*';
        $state = 'US' === $country && '*' === $state ? 'AL' : $state;
        // Defaults
        $currency = get_option('woocommerce_currency', 'GBP');
        $currency_pos = get_option('woocommerce_currency_pos', 'left');
        $decimal_sep = get_option('woocommerce_decimal_sep', '.');
        $thousand_sep = get_option('woocommerce_thousand_sep', ',');
        $dimension_unit = get_option('woocommerce_dimension_unit', 'cm');
        $weight_unit = get_option('woocommerce_weight_unit', 'kg');
        ?>
		<h1><?php 
        _e('Store Locale Setup', 'woocommerce');
        ?>
</h1>
		<form method="post">
			<table class="form-table">
				<tr>
					<th scope="row"><label for="store_location"><?php 
        _e('Where is your store based?', 'woocommerce');
        ?>
</label></th>
					<td>
					<select id="store_location" name="store_location" style="width:100%;" required data-placeholder="<?php 
        esc_attr_e('Choose a country&hellip;', 'woocommerce');
        ?>
" class="wc-enhanced-select">
							<?php 
        WC()->countries->country_dropdown_options($country, $state);
        ?>
						</select>
					</td>
				</tr>
				<tr>
					<th scope="row"><label for="currency_code"><?php 
        _e('Which currency will your store use?', 'woocommerce');
        ?>
</label></th>
					<td>
						<select id="currency_code" name="currency_code" required style="width:100%;" data-placeholder="<?php 
        esc_attr_e('Choose a currency&hellip;', 'woocommerce');
        ?>
" class="wc-enhanced-select">
							<option value=""><?php 
        _e('Choose a currency&hellip;', 'woocommerce');
        ?>
</option>
							<?php 
        foreach (get_woocommerce_currencies() as $code => $name) {
            echo '<option value="' . esc_attr($code) . '" ' . checked($currency, $code, false) . '>' . esc_html($name . ' (' . get_woocommerce_currency_symbol($code) . ')') . '</option>';
        }
        ?>
						</select>
						<span class="description"><?php 
        printf(__('If your currency is not listed you can %sadd it later%s.', 'woocommerce'), '<a href="http://docs.woothemes.com/document/add-a-custom-currency-symbol/" target="_blank">', '</a>');
        ?>
</span>
					</td>
				</tr>
				<tr>
					<th scope="row"><label for="currency_pos"><?php 
        _e('Currency Position', 'woocommerce');
        ?>
</label></th>
					<td>
						<select id="currency_pos" name="currency_pos" class="wc-enhanced-select">
							<option value="left" <?php 
        selected($currency_pos, 'left');
        ?>
><?php 
        echo __('Left', 'woocommerce');
        ?>
</option>
							<option value="right" <?php 
        selected($currency_pos, 'right');
        ?>
><?php 
        echo __('Right', 'woocommerce');
        ?>
</option>
							<option value="left_space" <?php 
        selected($currency_pos, 'left_space');
        ?>
><?php 
        echo __('Left with space', 'woocommerce');
        ?>
</option>
							<option value="right_space" <?php 
        selected($currency_pos, 'right_space');
        ?>
><?php 
        echo __('Right with space', 'woocommerce');
        ?>
</option>
//.........这里部分代码省略.........
开发者ID:zengskie,项目名称:Heroku-WordPress-PostgreSQL,代码行数:101,代码来源:class-wc-admin-setup-wizard.php

示例4: wc_get_customer_default_location

/**
 * Get the customer's default location. Filtered, and set to base location or left blank.
 *
 * If cache-busting, this should only be used when 'location' is set in the querystring.
 *
 * @todo should the woocommerce_default_country option be renamed to contain 'base'?
 * @since 2.3.0
 * @return array
 */
function wc_get_customer_default_location()
{
    switch (get_option('woocommerce_default_customer_address')) {
        case 'geolocation_ajax':
        case 'geolocation':
            $location = WC_Geolocation::geolocate_ip();
            // Base fallback
            if (empty($location['country'])) {
                $location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', get_option('woocommerce_default_country')));
            }
            break;
        case 'base':
            $location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', get_option('woocommerce_default_country')));
            break;
        default:
            $location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', ''));
            break;
    }
    return $location;
}
开发者ID:slavic18,项目名称:cats,代码行数:29,代码来源:wc-core-functions.php

示例5: init_geo_currency

 private function init_geo_currency()
 {
     $done = false;
     if ($this->is_use_geo_rules() and $this->is_first_unique_visit) {
         $rules = $this->get_geo_rules();
         $pd = WC_Geolocation::geolocate_ip();
         if (isset($pd['country']) and !empty($pd['country'])) {
             if (!empty($rules)) {
                 foreach ($rules as $curr => $countries) {
                     if (!empty($countries) and is_array($countries)) {
                         foreach ($countries as $country) {
                             if ($country == $pd['country']) {
                                 $this->storage->set_val('woocs_current_currency', $curr);
                                 $done = true;
                                 break 2;
                             }
                         }
                     }
                 }
             }
             /*
             * Array
              (
              [EUR] => Array
              (
              [0] => AF
              )
             
              [RUB] => Array
              (
              [0] => DZ
              [1] => AZ
              )
             
              )
             */
         }
     }
     return $done;
 }
开发者ID:Inteleck,项目名称:hwc,代码行数:40,代码来源:index.php

示例6: wcj_get_user_location

 /**
  * wcj_get_user_location.
  *
  * @version 2.5.0
  */
 function wcj_get_user_location()
 {
     $country = '';
     if (isset($_GET['country']) && '' != $_GET['country'] && wcj_is_user_role('administrator')) {
         $country = $_GET['country'];
     } else {
         // Get the country by IP
         $location = WC_Geolocation::geolocate_ip();
         // Base fallback
         if (empty($location['country'])) {
             $location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', get_option('woocommerce_default_country')));
         }
         $country = isset($location['country']) ? $location['country'] : '';
     }
     return $country;
 }
开发者ID:algoritmika,项目名称:woocommerce-jetpack,代码行数:21,代码来源:class-wcj-shortcodes.php

示例7: wcj_validate_eu_vat_number

 /**
  * wcj_validate_eu_vat_number.
  */
 function wcj_validate_eu_vat_number()
 {
     if (!isset($_GET['wcj_validate_eu_vat_number'])) {
         return;
     }
     if (isset($_GET['wcj_eu_vat_number_to_check']) && '' != $_GET['wcj_eu_vat_number_to_check']) {
         $eu_vat_number_to_check = substr($_GET['wcj_eu_vat_number_to_check'], 2);
         $eu_vat_number_country_to_check = substr($_GET['wcj_eu_vat_number_to_check'], 0, 2);
         if ('yes' === apply_filters('wcj_get_option_filter', 'no', get_option('wcj_eu_vat_number_check_ip_location_country', 'no'))) {
             $location = WC_Geolocation::geolocate_ip();
             if (empty($location['country'])) {
                 $location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', get_option('woocommerce_default_country')));
             }
             $is_valid = $location['country'] === $eu_vat_number_country_to_check ? validate_VAT($eu_vat_number_country_to_check, $eu_vat_number_to_check) : false;
         } else {
             $is_valid = validate_VAT($eu_vat_number_country_to_check, $eu_vat_number_to_check);
         }
     } else {
         $is_valid = null;
     }
     $_SESSION['wcj_is_eu_vat_number_valid'] = $is_valid;
     $_SESSION['wcj_eu_vat_number_to_check'] = $_GET['wcj_eu_vat_number_to_check'];
     echo $is_valid;
     die;
 }
开发者ID:yarwalker,项目名称:ecobyt,代码行数:28,代码来源:class-wcj-eu-vat-number.php

示例8: wc_get_customer_default_location

/**
 * Get the customer's default location.
 *
 * Filtered, and set to base location or left blank. If cache-busting,
 * this should only be used when 'location' is set in the querystring.
 *
 * @todo should the woocommerce_default_country option be renamed to contain 'base'?
 * @todo deprecate woocommerce_customer_default_location and support an array filter only to cover all cases.
 * @since 2.3.0
 * @return array
 */
function wc_get_customer_default_location()
{
    $location = array();
    switch (get_option('woocommerce_default_customer_address')) {
        case 'geolocation_ajax':
        case 'geolocation':
            // Exclude common bots from geolocation by user agent.
            $ua = wc_get_user_agent();
            if (!strstr($ua, 'bot') && !strstr($ua, 'spider') && !strstr($ua, 'crawl')) {
                $location = WC_Geolocation::geolocate_ip('', true, false);
            }
            // Base fallback.
            if (empty($location['country'])) {
                $location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', get_option('woocommerce_default_country')));
            }
            break;
        case 'base':
            $location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', get_option('woocommerce_default_country')));
            break;
        default:
            $location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', ''));
            break;
    }
    return apply_filters('woocommerce_customer_default_location_array', $location);
}
开发者ID:WPprodigy,项目名称:woocommerce,代码行数:36,代码来源:wc-core-functions.php

示例9: delete_option

}
/* rename options regions */
delete_option('_oga_wppbc_countries_groups');
add_option('wc_price_based_country_regions', $regions);
/* sync variable products */
require_once WC()->plugin_path() . '/includes/class-wc-product-variable.php';
$rows = $wpdb->get_results($wpdb->prepare("SELECT distinct post_parent FROM {$wpdb->posts} where post_type = %s", 'product_variation'));
foreach ($rows as $row) {
    WC_Product_Variable::sync($row->post_parent);
}
/* rename and update test options */
add_option('wc_price_based_country_test_mode', get_option('wc_price_based_country_debug_mode'));
delete_option('wc_price_based_country_debug_mode');
$test_ip = get_option('wc_price_based_country_debug_ip');
if ($test_ip) {
    $country = WC_Geolocation::geolocate_ip($test_ip);
    add_option('wc_price_based_country_test_country', $country['country']);
}
delete_option('wc_price_based_country_debug_ip');
/* unschedule geoip donwload */
if (wp_next_scheduled('wcpbc_update_geoip')) {
    wp_clear_scheduled_hook('wcpbc_update_geoip');
}
delete_option('wc_price_based_country_update_geoip');
// Delete de options older options
delete_option('_oga_wppbc_apiurl');
delete_option('_oga_wppbc_api_country_field');
// Delete geoip db
$geoip_db_dir = wp_upload_dir();
$geoip_db_dir = $geoip_db_dir['basedir'] . '/wc_price_based_country';
if (file_exists($geoip_db_dir . '/GeoLite2-Country.mmdb')) {
开发者ID:raminabsari,项目名称:phonicsschool,代码行数:31,代码来源:wcpbc-update-1.3.2.php

示例10: get_debug_info

 /**
 * get_debug_info.
 *
 	function get_debug_info( $args ) {
 		$html = '';
 		if ( 'yes' === get_option( 'wcj_price_by_country_local_enabled' ) ) {
 			$html .= '<p>';
 			$html .= __( 'Price by Country on per Product Basis is enabled.', 'woocommerce-jetpack' );
 			$html .= '</p>';
 		}
 
 		$data = array();
 		$data[] = array( '#', __( 'Countries', 'woocommerce-jetpack' ), __( 'Focus Country', 'woocommerce-jetpack' ), __( 'Regular Price', 'woocommerce-jetpack' ), __( 'Sale Price', 'woocommerce-jetpack' ) );
 		global $product;
 		for ( $i = 1; $i <= apply_filters( 'wcj_get_option_filter', 1, get_option( 'wcj_price_by_country_total_groups_number', 1 ) ); $i++ ) {
 
 			$row = array();
 
 			$row[] = $i;
 
 			$country_exchange_rate_group = get_option( 'wcj_price_by_country_exchange_rate_countries_group_' . $i );
 			$country_exchange_rate_group = str_replace( ' ', '', $country_exchange_rate_group );
 			$row[] = $country_exchange_rate_group;
 
 			$country_exchange_rate_group = explode( ',', $country_exchange_rate_group );
 			$_GET['country'] = $country_exchange_rate_group[0];
 			$row[] = $country_exchange_rate_group[0];
 			$currency_code = wcj_get_currency_symbol( get_option( 'wcj_price_by_country_exchange_rate_currency_group_' . $i ) );
 			$row[] = $product->get_regular_price() . ' ' . $currency_code;
 			$row[] = $product->get_sale_price() . ' ' . $currency_code;
 
 			$data[] = $row;
 		}
 		//$html .= wcj_get_table_html( $data, '', false );
 		$html = wcj_get_table_html( $data, array( 'table_heading_type' => 'vertical', ) );
 		return $html;
 	}
 
 	/**
 * fix_variable_product_price_on_sale.
 *
 	public function fix_variable_product_price_on_sale( $price, $product ) {
 		if ( $product->is_type( 'variable' ) ) {
 			if ( ! $product->is_on_sale() ) {
 				$start_position = strpos( $price, '<del>' );
 				$length = strpos( $price, '</del>' ) - $start_position;
 				// Fixing the price, i.e. removing the sale tags
 				return substr_replace( $price, '', $start_position, $length );
 			}
 		}
 		// No changes
 		return $price;
 	}
 
 	/**
 * get_customer_country_group_id.
 *
 * @version 2.2.6
 */
 public function get_customer_country_group_id()
 {
     // We already know the group - nothing to calculate - return group
     //		if ( null != $this->customer_country_group_id && $this->customer_country_group_id > 0 )
     //			return $this->customer_country_group_id;
     // We've already tried - no country was detected, no need to try again
     /* if ( -1 === $this->customer_country_group_id )
     			return null; */
     if (isset($_GET['country']) && '' != $_GET['country'] && is_super_admin()) {
         $country = $_GET['country'];
     } elseif ('yes' === get_option('wcj_price_by_country_override_on_checkout_with_billing_country', 'no') && is_checkout() && '' != WC()->customer->get_country()) {
         $country = WC()->customer->get_country();
     } else {
         if ('by_ip' === get_option('wcj_price_by_country_customer_country_detection_method', 'by_ip')) {
             // Get the country by IP
             $location = WC_Geolocation::geolocate_ip();
             // Base fallback
             if (empty($location['country'])) {
                 $location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', get_option('woocommerce_default_country')));
             }
             $country = isset($location['country']) ? $location['country'] : null;
         } elseif ('by_user_selection' === get_option('wcj_price_by_country_customer_country_detection_method', 'by_ip')) {
             /* $form_method  = get_option( 'wcj_price_by_country_country_selection_box_method', 'get' );
             			if ( 'get' == $form_method ) {
             				$country = ( isset( $_GET[ 'wcj-country' ] ) ) ? $_GET[ 'wcj-country' ] : null;
             			} else {
             				$country = ( isset( $_POST[ 'wcj-country' ] ) ) ? $_POST[ 'wcj-country' ] : null;
             			} */
             $country = isset($_SESSION['wcj-country']) ? $_SESSION['wcj-country'] : null;
         } elseif ('by_wpml' === get_option('wcj_price_by_country_customer_country_detection_method', 'by_ip')) {
             $country = defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : null;
         }
     }
     if (null === $country) {
         $this->customer_country_group_id = -1;
         return null;
     }
     // Get the country group id - go through all the groups, first found group is returned
     for ($i = 1; $i <= apply_filters('wcj_get_option_filter', 1, get_option('wcj_price_by_country_total_groups_number', 1)); $i++) {
         $country_exchange_rate_group = get_option('wcj_price_by_country_exchange_rate_countries_group_' . $i);
         $country_exchange_rate_group = str_replace(' ', '', $country_exchange_rate_group);
//.........这里部分代码省略.........
开发者ID:yarwalker,项目名称:ecobyt,代码行数:101,代码来源:class-wcj-price-by-country-core.php

示例11: init_geo_currency

 public function init_geo_currency()
 {
     $done = false;
     if ($this->is_use_geo_rules()) {
         $rules = $this->get_geo_rules();
         $pd = WC_Geolocation::geolocate_ip();
         $this->storage->set_val('woocs_user_country', $pd['country']);
         $is_allowed = $this->is_first_unique_visit and function_exists('wc_clean') and function_exists('wp_validate_redirect');
         if ($is_allowed) {
             if (isset($pd['country']) and !empty($pd['country'])) {
                 if (!empty($rules)) {
                     foreach ($rules as $curr => $countries) {
                         if (!empty($countries) and is_array($countries)) {
                             foreach ($countries as $country) {
                                 if ($country == $pd['country']) {
                                     $this->storage->set_val('woocs_current_currency', $curr);
                                     $this->current_currency = $curr;
                                     $done = true;
                                     break 2;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->storage->set_val('woocs_first_unique_visit', 1);
     return $done;
 }
开发者ID:websideas,项目名称:Mondova,代码行数:30,代码来源:index.php

示例12: get_customer_country_by_ip

 /**
  * get_customer_country_by_ip.
  *
  * @version 2.5.1
  * @since   2.5.0
  */
 function get_customer_country_by_ip()
 {
     if (class_exists('WC_Geolocation')) {
         // Get the country by IP
         $location = WC_Geolocation::geolocate_ip();
         // Base fallback
         if (empty($location['country'])) {
             $location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', get_option('woocommerce_default_country')));
         }
         return isset($location['country']) ? $location['country'] : null;
     } else {
         return null;
     }
 }
开发者ID:algoritmika,项目名称:woocommerce-jetpack,代码行数:20,代码来源:class-wcj-price-by-country-core.php

示例13: get_customer_country_group_id

 /**
  * get_customer_country_group_id.
  */
 public function get_customer_country_group_id()
 {
     // We already know the group - nothing to calculate - return group
     //		if ( null != $this->customer_country_group_id && $this->customer_country_group_id > 0 )
     //			return $this->customer_country_group_id;
     // We've already tried - no country was detected, no need to try again
     if (-1 === $this->customer_country_group_id) {
         return null;
     }
     if (isset($_GET['country']) && '' != $_GET['country'] && is_super_admin()) {
         $country = $_GET['country'];
     } else {
         // Get the country by IP
         $location = WC_Geolocation::geolocate_ip();
         // Base fallback
         if (empty($location['country'])) {
             $location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', get_option('woocommerce_default_country')));
         }
         $country = isset($location['country']) ? $location['country'] : null;
     }
     if (null === $country) {
         $this->customer_country_group_id = -1;
         return null;
     }
     // Get the country group id - go through all the groups, first found group is returned
     for ($i = 1; $i <= apply_filters('wcj_get_option_filter', 1, get_option('wcj_price_by_country_total_groups_number', 1)); $i++) {
         $country_exchange_rate_group = get_option('wcj_price_by_country_exchange_rate_countries_group_' . $i);
         $country_exchange_rate_group = str_replace(' ', '', $country_exchange_rate_group);
         $country_exchange_rate_group = explode(',', $country_exchange_rate_group);
         if (in_array($country, $country_exchange_rate_group)) {
             $this->customer_country_group_id = $i;
             //wcj_log( 'customer_country_group_id=' . $this->customer_country_group_id );
             return $i;
         }
     }
     // No country group found
     $this->customer_country_group_id = -1;
     return null;
 }
开发者ID:sawan34,项目名称:tanzi,代码行数:42,代码来源:class-wcj-price-by-country-core.php


注:本文中的WC_Geolocation::geolocate_ip方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。