Most of our plugins include a geolocation mechanism that is triggered automatically, as needed. The detection relies on the MaxMind GeoIP database, which is quite reliable. Support for CloudFlare geolocation is also built-in: when our plugins detect the presence of the country detected by CloudFlare, that value is used immediately, without loading the MaxMind database.
In case your environment already includes a geolocation solution, and you would like to use it instead of the one we provide, you can do so by implementing a filter for the wc_aelia_ip2location_before_get_country_code hook. When such filter returns a valid country code, the built-in geolocation detection logic is skipped, and the returned code is used instead.
The code in the examples affects with all our plugins that use geolocation. If you use multiple Aelia plugins, you will only have to implement the code once, and they will all use the country code returned by your customisation.
WooCommerce Examples
Example 1 - Using your own geolocation function
/** * Uses a custom geolocation function to detect customer's location. * * @param string country_code The country code passed by previous filters (if any). * @return string A country code, or an empty string if the country could not be detected. */ add_filter('wc_aelia_ip2location_before_get_country_code', function($country_code) { // Call your custom geolocation function to set the country code $country_code = your_custom_geolocation_function(); return $country_code; }, 10, 1);
Example 2 - Using the geolocation feature provided by WP Engine
/** * Uses a custom geolocation function to detect customer's location. * * @param string country_code The country code passed by previous filters (if any). * @return string A country code, or an empty string if a country code was not passed * by WP Engine. */ add_filter('wc_aelia_ip2location_before_get_country_code', function($country_code) { // Return the country code detected by WP Engine, if it was set if(!empty($_SERVER['HTTP_GEOIP_COUNTRY_CODE'])) { $country_code = $_SERVER['HTTP_GEOIP_COUNTRY_CODE']; } return $country_code; }, 10, 1);
You can purchase our ecommerce internationalisation solutions from our online shop.