• Hi,

    I’ve setup 1 warehouses location (so default USA and EURO) and i’ve tried to set the location detection by country (e.g. IT,FR) and by “Connected WarehousesShipping Zone” but the stock quantity is fetched from the default one even though I’m connecting from Milan (Italy). The currency plugin is showing properly euros instead of dollars.

    The EURO shipping zone is set with the counties Italy & France, am I missing something in the configuration to make work by “Connected WarehousesShipping Zone”? can you advise some troubleshooting (code included)?

    A smaller issue is that the link “See country codes list” in woocommerce->settings->warehouses-> edit Euro warehouse is not working, I’ve assumed it’s the standard 2 digits country code.

    Thank you!

    • This topic was modified 5 years, 4 months ago by allanext.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter allanext

    (@allanext)

    So, the issue is that the environment variables

    HTTP_GEOIP_COUNTRY_CODE
    HTTP_GEOIP_POSTAL_CODE

    are not set, not sure on which GEO module you rely on or if it’s supposed to be part of woocommerce, i’ve changed the following to use a function from geoip-detect module to make it work:

    private static function auto_warehouse_switch()
    {
        global $SHIPPING_ZONES_ENABLED;
        $found_warehouse = false;
    
        $geo_country_code = trim(strtoupper(getenv( 'HTTP_GEOIP_COUNTRY_CODE' )));
        $geo_postal_code = trim(strtoupper(getenv( 'HTTP_GEOIP_POSTAL_CODE' )));
    		
        //PC::debug("GEO COUNTRY: $geo_country_code", "WAREHOUSE GEO");
        //PC::debug("POSTAL CODE: $geo_postal_code", "WAREHOUSE GEO");
        $geoInfo = geoip_detect2_get_info_from_current_ip();
        $geo_country_code=($geoInfo->country->isoCode);
        //PC::debug("GEO COUNTRY AFTER: $geo_country_code", "WAREHOUSE GEO");
    
        $alt_warehouses_list = self::get_alt_warehouses_list();
    • This reply was modified 5 years, 4 months ago by allanext.
    • This reply was modified 5 years, 4 months ago by allanext.
    Plugin Author Joel

    (@joeleem0n)

    @allanext This should be fixed for you.

    Thread Starter allanext

    (@allanext)

    Hi @joeleem0n,

    in version 1.2.6 i still have the geo-location issue, what are the requirements to have these two environment variables set?

    HTTP_GEOIP_COUNTRY_CODE
    HTTP_GEOIP_POSTAL_CODE

    as did above i’ve added the following lines in the file calss-warehouse-woocommerce-public.php:

    
    // automatically detect location and switch warehouse
    private static function auto_warehouse_switch()
    {
      global $SHIPPING_ZONES_ENABLED;
      $found_warehouse = false;
    
      $geo_country_code = trim(strtoupper(getenv( 'HTTP_GEOIP_COUNTRY_CODE' )));
      $geo_postal_code = trim(strtoupper(getenv( 'HTTP_GEOIP_POSTAL_CODE' )));
      $geoInfo = geoip_detect2_get_info_from_current_ip();
      $geo_country_code=($geoInfo->country->isoCode);
    

    Thank you @joeleem0n

    • This reply was modified 5 years, 1 month ago by allanext.
    Plugin Author Joel

    (@joeleem0n)

    @allanext

    Okay. so we forgot to add notes about the GeoTarget feature.

    https://share.getcloudapp.com/OAuLDJew

    you’ll need to allow that feature in your server configs. We use this for example:

    https://www.ads-software.com/plugins/wpengine-geoip/

    Thread Starter allanext

    (@allanext)

    Hi @joeleem0n,

    I’ve updated to 1.3.3:

    1 – I can’t see the sentence that states that WP Engine is required to run the geolocation (no bid deal)

    2 – First thing that i’ve notice is this PHP fatal error that crashes the site

    [Tue Apr 21 15:26:17.743069 2020] [:error] [pid 30871] [client 68.192.44.174:53780] PHP Fatal error: Uncaught Error: Call to undefined method MaxMind\\Db\\Reader::getWithPrefixLen() in /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/vendor/geoip2/geoip2/src/Database/Reader.php:246\nStack trace:\n#0 /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/vendor/geoip2/geoip2/src/Database/Reader.php(217): GeoIp2\\Database\\Reader->getRecord(‘City’, ‘City’, ‘68.192.44.174’)\n#1 /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/vendor/geoip2/geoip2/src/Database/Reader.php(73): GeoIp2\\Database\\Reader->modelFor(‘City’, ‘City’, ‘68.192.44.174’)\n#2 /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/class-warehouse-popups-woocommerce-public.php(368): GeoIp2\\Database\\Reader->city(‘68.192.44.174’)\n#3 /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/class-warehouse-popups-woocommerce-public.php(430): Warehouse_Popups_Woocommerce_Public::auto_warehou in /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/vendor/geoip2/geoip2/src/Database/Reader.php on line 246

    3 – I’ve tried wpengine-geoip but the plugin will not work without a subscription:

    WP Engine GeoTarget requires a WP Engine account with GeoTarget enabled for full functionality. Only testing queries will work on this site.

    4 – Why not use “Geolocation IP Detection” that rates 5 stars, with 44 reviews, used by more than 20K sites and that is free? you would call instead:

    geoip_detect2_get_info_from_ip($ip, $locales = array(‘en’), $options = array())

    The plugin also updates the ip databases automatically from MaxMind and others.

    5 – Oh, i’ve noticed that you are using a database of IP directly in the plugin but i still get the error on point 2

    Thread Starter allanext

    (@allanext)

    Hi @joeleem0n ,

    ok, i see that you are trying to read the local ip database from geoip2; not sure why it gives the PHP fatal error:

    [Tue Apr 21 15:26:17.743069 2020] [:error] [pid 30871] [client 68.192.44.174:53780] PHP Fatal error: Uncaught Error: Call to undefined method MaxMind\\Db\\Reader::getWithPrefixLen() in /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/vendor/geoip2/geoip2/src/Database/Reader.php:246\nStack trace:\n#0 /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/vendor/geoip2/geoip2/src/Database/Reader.php(217): GeoIp2\\Database\\Reader->getRecord(‘City’, ‘City’, ‘68.192.44.174’)\n#1 /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/vendor/geoip2/geoip2/src/Database/Reader.php(73): GeoIp2\\Database\\Reader->modelFor(‘City’, ‘City’, ‘68.192.44.174’)\n#2 /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/class-warehouse-popups-woocommerce-public.php(368): GeoIp2\\Database\\Reader->city(‘68.192.44.174’)\n#3 /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/class-warehouse-popups-woocommerce-public.php(430): Warehouse_Popups_Woocommerce_Public::auto_warehou in /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/vendor/geoip2/geoip2/src/Database/Reader.php on line 246

    I’ve done the following changes to the file “class-warehouse-popups-woocommerce-public.php” to make it work with the “Geo ip detection” plugin (personally i think it’s better than maintain the external library in your plugin):

    Beginning of file:

    <?php
    if ( ! defined( 'ABSPATH' ) ) {
    	exit; // Exit if accessed directly
    }
    
    //require 'vendor/autoload.php';
    use GeoIp2\Database\Reader;

    Commented reading the geolite from the local file (that gives the error above) with:

    // automatically detect location and switch warehouse
        private static function auto_warehouse_switch()
        {
    		
            global $SHIPPING_ZONES_ENABLED;
            $found_warehouse = false;
    
    		//$reader = new Reader(plugin_dir_path( __FILE__ ) . 'GeoLite2-City.mmdb');
    		
    		if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
    		    $ip_address = $_SERVER['HTTP_CLIENT_IP'];
    		} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    			$ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
    		} else {
    			$ip_address = $_SERVER['REMOTE_ADDR'];
    		}
    
    		if($ip_address == '127.0.0.1') {
    			self::set_warehouse_cookie($_REQUEST['wh_popups_change_wh_to']);
    			return;
    		}
    
    		// $record = $reader->city($ip_address);
            // $geo_country_code = trim(strtoupper($record->country->isoCode));
    		// $geo_postal_code = trim($record->postal->code);
    		
    		$geoInfo = geoip_detect2_get_info_from_current_ip();
    		$geo_country_code=($geoInfo->country->isoCode);
    		$geo_postal_code=($geoInfo->postal->code);
    
            $alt_warehouses_list = self::get_alt_warehouses_list();

    what do you think about calling the geoip_detect2_get_info_from_current_ip() instead of opening the ip database file?

    Thank you

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Warehouse location detection issue’ is closed to new replies.