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


PHP WC_Geolocation类代码示例

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


在下文中一共展示了WC_Geolocation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例4: get_database_info

 /**
  * Get array of database information. Version, prefix, and table existence.
  *
  * @return array
  */
 public function get_database_info()
 {
     global $wpdb;
     // WC Core tables to check existence of
     $tables = apply_filters('woocommerce_database_tables', array('woocommerce_sessions', 'woocommerce_api_keys', 'woocommerce_attribute_taxonomies', 'woocommerce_downloadable_product_permissions', 'woocommerce_order_items', 'woocommerce_order_itemmeta', 'woocommerce_tax_rates', 'woocommerce_tax_rate_locations', 'woocommerce_shipping_zones', 'woocommerce_shipping_zone_locations', 'woocommerce_shipping_zone_methods', 'woocommerce_payment_tokens', 'woocommerce_payment_tokenmeta'));
     if (get_option('db_version') < 34370) {
         $tables[] = 'woocommerce_termmeta';
     }
     $table_exists = array();
     foreach ($tables as $table) {
         $table_exists[$table] = $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s;", $wpdb->prefix . $table)) === $wpdb->prefix . $table;
     }
     // Return all database info. Described by JSON Schema.
     return array('wc_database_version' => get_option('woocommerce_db_version'), 'database_prefix' => $wpdb->prefix, 'maxmind_geoip_database' => WC_Geolocation::get_local_database_path(), 'database_tables' => $table_exists);
 }
开发者ID:Korkey128k,项目名称:woocommerce,代码行数:20,代码来源:class-wc-rest-system-status-controller.php

示例5: create_order

 /**
  * Create an order. Error codes:
  * 		520 - Cannot insert order into the database.
  * 		521 - Cannot get order after creation.
  * 		522 - Cannot update order.
  * 		525 - Cannot create line item.
  * 		526 - Cannot create fee item.
  * 		527 - Cannot create shipping item.
  * 		528 - Cannot create tax item.
  * 		529 - Cannot create coupon item.
  *
  * @throws Exception
  * @param  $data Posted data.
  * @return int|WP_ERROR
  */
 public function create_order($data)
 {
     // Give plugins the opportunity to create an order themselves.
     if ($order_id = apply_filters('woocommerce_create_order', null, $this)) {
         return $order_id;
     }
     try {
         $order_id = absint(WC()->session->get('order_awaiting_payment'));
         $cart_hash = md5(json_encode(wc_clean(WC()->cart->get_cart_for_session())) . WC()->cart->total);
         /**
          * If there is an order pending payment, we can resume it here so
          * long as it has not changed. If the order has changed, i.e.
          * different items or cost, create a new order. We use a hash to
          * detect changes which is based on cart items + order total.
          */
         if ($order_id && ($order = wc_get_order($order_id)) && $order->has_cart_hash($cart_hash) && $order->has_status(array('pending', 'failed'))) {
             // Action for 3rd parties.
             do_action('woocommerce_resume_order', $order_id);
             // Remove all items - we will re-add them later.
             $order->remove_order_items();
         } else {
             $order = new WC_Order();
         }
         foreach ($data as $key => $value) {
             if (is_callable(array($order, "set_{$key}"))) {
                 $order->{"set_{$key}"}($value);
             }
         }
         $order->set_created_via('checkout');
         $order->set_cart_hash($cart_hash);
         $order->set_customer_id(apply_filters('woocommerce_checkout_customer_id', get_current_user_id()));
         $order->set_currency(get_woocommerce_currency());
         $order->set_prices_include_tax('yes' === get_option('woocommerce_prices_include_tax'));
         $order->set_customer_ip_address(WC_Geolocation::get_ip_address());
         $order->set_customer_user_agent(wc_get_user_agent());
         $order->set_customer_note(isset($data['order_comments']) ? $data['order_comments'] : '');
         $order->set_payment_method($data['payment_method']);
         $order->set_shipping_total(WC()->cart->shipping_total);
         $order->set_discount_total(WC()->cart->get_cart_discount_total());
         $order->set_discount_tax(WC()->cart->get_cart_discount_tax_total());
         $order->set_cart_tax(WC()->cart->tax_total);
         $order->set_shipping_tax(WC()->cart->shipping_tax_total);
         $order->set_total(WC()->cart->total);
         $this->create_order_line_items($order);
         $this->create_order_fee_lines($order);
         $this->create_order_shipping_lines($order);
         $this->create_order_tax_lines($order);
         $this->create_order_coupon_lines($order);
         $order_id = $order->save();
         // Let plugins add their own meta data.
         do_action('woocommerce_checkout_update_order_meta', $order_id, $data);
         return $order_id;
     } catch (Exception $e) {
         return new WP_Error('checkout-error', $e->getMessage());
     }
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:71,代码来源:class-wc-checkout.php

示例6: 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

示例7: 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

示例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'?
 * @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

示例9: isset

                            $country_code = isset($data->country_code) ? $data->country_code : '';
                            break;
                        default:
                            $country_code = apply_filters('woocommerce_geolocation_geoip_response_' . $service_name, '', $response['body']);
                            break;
                    }
                    $country_code = sanitize_text_field(strtoupper($country_code));
                    if ($country_code) {
                        break;
                    }
                }
            }
            set_transient('geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS);
        }
        return $country_code;
    }
    /**
     * Test if is IPv6
     *
     * @since  2.4.0
     *
     * @param  string $ip_address
     * @return bool
     */
    private static function is_IPv6($ip_address)
    {
        return false !== filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
    }
}
WC_Geolocation::init();
开发者ID:slavic18,项目名称:cats,代码行数:30,代码来源:class-wc-geolocation.php

示例10: 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

示例11: 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

示例12: 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

示例13: get_user_ip

 /**
  * Get user's IP address
  */
 public function get_user_ip()
 {
     return WC_Geolocation::get_ip_address();
 }
开发者ID:jfitzsimmons,项目名称:soundtrackforspace,代码行数:7,代码来源:class-wc-gateway-paypal-pro.php

示例14: 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

示例15: 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


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