businessdad icon

Aelia Currency Switcher - Use Cloudways country geolocation

businessdad | PRO | 06/21/20 04:24:04 PM UTC | 0 ⭐ | 2695 👁️ | Never ⏰ | []
PHP |

1.8 KB

|

None

|

0 👍

/

0 👎

/**
 * Aelia Currency Switcher - Fetch the geolocation country from Cloudways.
 * The code in this example will take the country from the header set by Cloudways 
 * (if present) and skip the internal geolocation logic used by the Aelia plugins, such
 * as Aelia Currency Switcher, Aelia Prices by Country and Aelia Tax Display by Country.
 * 
 * For more information about the geolocation feature offered by Cloudways, please
 * refer to their documentation: https://support.cloudways.com/use-geoip-with-your-application/
 * 
 * IMPORTANT
 * Plugins like the Aelia Tax Display by Country also handle the county/province/state, 
 * which Cloudways doesn't return. In that case, the plugin will still use its internal 
 * logic to fetch that information.
 *
 * GPL DISCLAIMER
 * THE USE OF THIS CODE IS AS YOUR OWN RISK.
 * This code is provided free of charge and comes without any warranty, implied or explicit, to the extent permitted
 * by applicable law. Except when otherwise stated in writing the copyright holders and/or other parties provide the
 * program "as is" without warranty of any kind, either expressed or implied, including, but not limited to, the implied
 * warranties of merchantability and fitness for a particular purpose. The entire risk as to the quality and performance
 * of the program is with you. Should the program prove defective, you assume the cost of all necessary servicing, repair
 * or correction.
 *
 * Need a consultation, or assistance to customise this code? Find us on Codeable: https://aelia.co/hire_us
 */
 
add_filter('wc_aelia_ip2location_before_get_country_code', function($country, $ip_address) {
  // Return the country from the header set by Cloudways
  return isset($_SERVER['HTTP_X_FORWARDED_COUNTRY']) ? $_SERVER['HTTP_X_FORWARDED_COUNTRY'] : $country;
}, 10, 2);

Comments