/**
* Redirects visitors based on their country of origin.
* Need help customising the code for your need? Hire us on Codeable: http://bit.ly/codeable_aelia
*
* @author Aelia <[email protected]>
* @link https://aelia.co
*/
add_action('template_redirect', function() {
$country = '';
// Cookie "aelia_customer_country" contains the country detected by the Aelia
// plugins
if(!empty($_COOKIE['aelia_customer_country'])) {
$country = $_COOKIE['aelia_customer_country'];
}
// Cookie "aelia_billing_country" is a legacy cookie, used by older versions
// of the plugins
if(empty($country) && !empty($_COOKIE['aelia_billing_country'])) {
$country = $_COOKIE['aelia_billing_country'];
}
// The redirect map will associate each country to the redirect destination
$redirect_map = array(
'UK' => 'https://site-for-uk.org',
'US' => 'https://site-for-us.org',
'DE' => 'https://site-for-germany.org',
)
// If we have a destination for a specific country, redirect the user
if(!empty($redirect_map[$country])) {
wp_redirect($redirect_map[$country]);
exit;
}
});
Comments