I am using the plugin FOX – Currency Switcher Professional for WooCommerce (former name is WOOCS) and everything was working smoothly. Then I have installed a budgeter plugin. Unfortunately, it is not multicurrency and not compatible with the Currency Switcher.
Therefore, I had to create two instances of the budgeter: one for Argentine pesos and another for dollars. These two instances are loaded on the same page,"/prices/", and from the Divi Builder create two code modules that display according to a conditional: if the "ARS" parameter of currency exists in the URL, display the module that has the shortcode of the budget in pesos; instead, if there is "USD" as a currency parameter in the URL, then hide the other one and load the budgeter in dollars.
In the WOOCS module I have geolocation activated, and it takes ARS only for Argentina, for the rest of the countries it takes dollars.
But sometimes works and sometimes not. Recently, I have checked it three times: Argentina (worked), EU (worked), Argentina again (worked), Brasil (didn t work). They were all consecutive tests: Changing the location on the VPN, checking the IP at whatismyipaddress.com and then opening a new incognito window.
I ve not caching plugins enabled.
This is the code I have installed on my site to add the currency parameter:
function agregar_moneda_a_url() {
global $WOOCS;
$current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$parsed_url = parse_url($current_url);
if (isset($parsed_url[ query ]) && !empty($parsed_url[ query ])) {
$params = [];
parse_str($parsed_url[ query ], $params);
if (isset($params[ currency ])) {
return; // El parámetro"currency" ya está presente en la URL, no se hace nada
}
}
if (is_page( precios )) {
$moneda = $WOOCS->current_currency;
$new_url = add_query_arg( currency , $moneda, $current_url);
wp_redirect($new_url);
exit;
}
}
add_action( template_redirect , agregar_moneda_a_url );
As you can see, when it doesn t work, the URL takes the value of currency configured as initial in the plugin options, not the one it should according to the geolocation. However, the currency exchanger is taking the value of currency according to the geolocation.
I understand that I am close to the solution, but I must be loading the code at the wrong time, right? If it loaded the code at the same time or after the multi-currency plugin takes the geolocation value, then it should take the correct value from WOOCS variable.
If you could guide me with this, I would really appreciate it.