Quote from Marito Ce on July 10, 2023, 15:09
hi Pablo again!
I've solved it! =)
I've used Woocommerce geoip functions instead Woocs to assgign my currency params. I copy the code below in case it helps someone:
// Agergar parámetro currency en la página de Precios
//
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')) {
$geoData = WC_Geolocation::geolocate_ip();
$country = $geoData['country'];
switch ( $country ) {
case "AR":
$moneda = "ARS";
break;
default:
$moneda = "USD";
}
$new_url = add_query_arg('currency', $moneda, $current_url);
wp_redirect($new_url);
exit;
}
}
add_action('template_redirect', 'agregar_moneda_a_url');
Thanks a lot! =)
Regards!
hi Pablo again!
I've solved it! =)
I've used Woocommerce geoip functions instead Woocs to assgign my currency params. I copy the code below in case it helps someone:
// Agergar parámetro currency en la página de Precios
//
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')) {
$geoData = WC_Geolocation::geolocate_ip();
$country = $geoData['country'];
switch ( $country ) {
case"AR":
$moneda ="ARS";
break;
default:
$moneda ="USD";
}
$new_url = add_query_arg('currency', $moneda, $current_url);
wp_redirect($new_url);
exit;
}
}
add_action('template_redirect', 'agregar_moneda_a_url');
Thanks a lot! =)
Regards!