/** * Get settings array * * @return array */ public function get_settings() { if (file_exists(TFLS_GEOIP_DB)) { $next_update = wp_next_scheduled('tfls_update_geoip'); $debug_country = ''; $debug_ip = get_option('wc_tfls_debug_ip'); if ($debug_ip) { $debug_country = WC()->countries->countries[get_country_from_ip($debug_ip)]; } return array(array('title' => __('Pricing groups', 'woocommerce-tfls'), 'type' => 'title', 'desc' => 'Pricing groups are listed below. Add a group for each price you need to add to products and include the countries for which this price will be displayed. For deleted a group, check "Delete" and save changes', 'id' => 'tfls_groups'), array('type' => 'country_groups'), array('type' => 'sectionend', 'id' => 'tfls_groups'), array('title' => __('GeoIp Database', 'woocommerce-tfls'), 'type' => 'title', 'desc' => 'This product includes GeoLite2 data created by MaxMind, available from <a href="http://www.maxmind.com">http://www.maxmind.com</a>.', 'id' => 'tfls_geoip'), array('title' => __('Auto update GeoIP', 'woocommerce-tfls'), 'desc' => __('Download GeoIP Database Once Every 4 Weeks', 'woocommerce-tfls'), 'id' => 'wc_tfls_update_geoip', 'default' => 'yes', 'type' => 'checkbox', 'desc_tip' => $next_update ? sprintf(__('Next update at %s', 'woocommerce-tfls'), date_i18n('Y-m-d H:i', $next_update)) : ''), array('type' => 'sectionend', 'id' => 'tfls_geoip'), array('title' => __('Debug Mode', 'woocommerce-tfls'), 'type' => 'title', 'desc' => 'If you want to check that prices are shown successfully, enable debug mode and enter the IP with which you want to try.', 'id' => 'tfls_debug'), array('title' => __('Enabled/Disabled', 'woocommerce-tfls'), 'desc' => __('Enabled debug mode', 'woocommerce-tfls'), 'id' => 'wc_tfls_debug_mode', 'default' => 'no', 'type' => 'checkbox'), array('title' => __('Debugging IP', 'woocommerce-tfls'), 'id' => 'wc_tfls_debug_ip', 'desc' => $debug_country, 'default' => '', 'type' => 'text'), array('type' => 'sectionend', 'id' => 'tfls_debug')); } else { return array(array('title' => __('Download GeoIP Database', 'woocommerce-tfls'), 'type' => 'title', 'desc' => __('WooCommerce Price Based on Countries works with MaxMind GeoIP DataBase, to activate check “Download GeoIP Database” and Save changes.', 'woocommerce-tfls'), 'id' => 'tfls_options'), array('title' => __('Enabled Price Based on Country', 'woocommerce-tfls'), 'desc' => __('Download GeoIP Database', 'woocommerce-tfls'), 'id' => 'wc_tfls_update_geoip', 'default' => 'yes', 'type' => 'checkbox'), array('type' => 'sectionend', 'id' => 'tfls_options')); } }
function country_from_client_ip() { $debug_ip = get_option('tfls_debug_ip'); $debug_enabled = get_option('tfls_debug_mode'); if ($debug_enabled && !empty($debug_ip)) { $client_ip = $debug_ip; } else { if (isset($_SERVER['HTTP_CLIENT_IP']) && $_SERVER['HTTP_CLIENT_IP']) { $client_ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']) { $client_ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $client_ip = $_SERVER['REMOTE_ADDR']; } } return get_country_from_ip($client_ip); }