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'); } }
/** * 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; }
/** * 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…', '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…', 'woocommerce'); ?> " class="wc-enhanced-select"> <option value=""><?php _e('Choose a currency…', '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> </select> </td> </tr> <tr> <th scope="row"><label for="thousand_sep"><?php _e('Thousand Separator', 'woocommerce'); ?> </label></th> <td> <input type="text" id="thousand_sep" name="thousand_sep" size="2" value="<?php echo esc_attr($thousand_sep); ?> " /> </td> </tr> <tr> <th scope="row"><label for="decimal_sep"><?php _e('Decimal Separator', 'woocommerce'); ?> </label></th> <td> <input type="text" id="decimal_sep" name="decimal_sep" size="2" value="<?php echo esc_attr($decimal_sep); ?> " /> </td> </tr> <tr> <th scope="row"><label for="weight_unit"><?php _e('Which unit should be used for product weights?', 'woocommerce'); ?> </label></th> <td> <select id="weight_unit" name="weight_unit" class="wc-enhanced-select"> <option value="kg" <?php selected($weight_unit, 'kg'); ?> ><?php echo __('kg', 'woocommerce'); ?> </option> <option value="g" <?php selected($weight_unit, 'g'); ?> ><?php echo __('g', 'woocommerce'); ?> </option> <option value="lbs" <?php selected($weight_unit, 'lbs'); ?> ><?php echo __('lbs', 'woocommerce'); ?> </option> <option value="oz" <?php selected($weight_unit, 'oz'); ?> ><?php echo __('oz', 'woocommerce'); ?> </option> </select> </td> </tr> <tr> <th scope="row"><label for="dimension_unit"><?php _e('Which unit should be used for product dimensions?', 'woocommerce'); ?> </label></th> <td> <select id="dimension_unit" name="dimension_unit" class="wc-enhanced-select"> <option value="m" <?php selected($dimension_unit, 'm'); ?> ><?php echo __('m', 'woocommerce'); ?> </option> <option value="cm" <?php selected($dimension_unit, 'cm'); ?> ><?php echo __('cm', 'woocommerce'); ?> </option> <option value="mm" <?php selected($dimension_unit, 'mm'); ?> ><?php echo __('mm', 'woocommerce'); ?> </option> <option value="in" <?php selected($dimension_unit, 'in'); ?> ><?php echo __('in', 'woocommerce'); ?> </option> <option value="yd" <?php selected($dimension_unit, 'yd'); ?> ><?php echo __('yd', 'woocommerce'); ?> </option> </select> </td> </tr> </table> <p class="wc-setup-actions step"> <input type="submit" class="button-primary button button-large" value="<?php esc_attr_e('Continue', 'woocommerce'); ?> " name="save_step" /> <a href="<?php echo esc_url($this->get_next_step_link()); ?> " class="button button-large"><?php _e('Skip this step', 'woocommerce'); ?> </a> <?php wp_nonce_field('wc-setup'); ?> </p> </form> <?php }
/** * 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; }
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; }
/** * 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; }
/** * 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; }
/** * 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); }
} /* 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')) {
/** * 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); $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; }
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; }
/** * 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; } }
/** * 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; }