Answer the question
In order to leave comments, you need to log in
How to lower function priority in PHP?
In my Woocommerce store, I use several currencies and their switch is a dropdown switcher (<?php echo(do_shortcode('[currency_switcher]')); ?>). There is a code that sets a specific currency by geolocation, but then the manual mode switch stops working. I do not understand how to change the code to either lower the priority of the function or use it only on the first load? For geolocation to work, but manually it could be changed.
function geoIPLocator() {
global $woocommerce_wpml;
$currency='EUR';
$geo=new WC_Geolocation();
$geo->init();
$country=$geo::geolocate_ip($geo::get_ip_address());
if(isset($_SESSION['locator'])) {
if($_SESSION['locator']['IP']==$_SERVER['REMOTE_ADDR'] && strlen($_SESSION['locator']['IP'])>0) {
$woocommerce_wpml->multi_currency_support->set_client_currency($_SESSION['locator']['currency']);
return;
}
}
if($country['country']=="RU" || $country['country']=="BY") {
$woocommerce_wpml->multi_currency_support->set_client_currency('RUB');
$currency='RUB';
} else {
$woocommerce_wpml->multi_currency_support->set_client_currency('EUR');
$currency='EUR';
}
$_SESSION['locator']=array("IP"=>$_SERVER['REMOTE_ADDR'], "ISO"=>$country['country'], "currency"=>$currency);
}
add_action( 'init', 'geoIPLocator', 5);
Answer the question
In order to leave comments, you need to log in
It is necessary to save the current currency in the session and, when determining by geolocation, check if there is a value there, if not, then we determine by geolocation.
but the switch does not look at anything and just changes the currency and saves it to the session
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question