/** * This function works out the most likely country for the current order. * * @param Boolean $recalculate * * @return String - Country Code - e.g. NZ **/ public static function get_country($recalculate = false) { if (self::$get_country_cache === null || $recalculate) { $countryCode = ''; //1. fixed country is first $countryCode = self::get_fixed_country_code(); if (!$countryCode) { //2. check shipping address if ($o = ShoppingCart::current_order()) { $countryCode = $o->Country(); } //3. check GEOIP information if (!$countryCode) { $countryCode = self::get_country_from_ip(); //4 check default country set in GEO IP.... if (!$countryCode) { $countryCode = EcommerceConfig::get('EcommerceCountry', 'default_country_code'); //5. take the FIRST country from the get_allowed_country_codes if (!$countryCode) { $countryArray = self::list_of_allowed_entries_for_dropdown(); if (is_array($countryArray) && count($countryArray)) { foreach ($countryArray as $countryCode => $countryName) { //we stop at the first one... as we have no idea which one is the best. break; } } } } } } self::$get_country_cache = $countryCode; } return self::$get_country_cache; }