Hi @fredy121 ,
hope you’re fine ? Sorry for the issue you’re facing. Do you have activate the autoswitch option from Weglot ? It may be a conflict with our features and yours. Can you check the log to have the details of the error when you run the function si_geolocate_visitor() ?
Regards
Hi @glx77
I am good, thanks. Hope you are doing good too.
The autoswitch option in Weglot is not active and there are no error logs while running the function. On page load an ajax request is submitted which then returns the visitor geolocation details. This request is failing without any error details and I tried console logging the error. The only error visible is in developer tools console net::ERR_TOO_MANY_REDIRECTS
Thanks
Hi @fredy121 ,
I’m good too thanks. That’s weird, if the autoswitch is not activate, weglot don’t make any redirection. I investigate and get you in touch. Are you able to track where the redirection come from ? Or can you send me the content of your si_geolocate_visitor() function, i’ll would like to test it in my side to find a solution
Regards
Hi @glx77
Unfortunately I couldn’t track where the redirection are coming from. These are my codes
$.ajax( {
method: 'post',
url: si.ajaxUrl,
data: {
'action': 'si_geolocate_visitor'
},
dataType: 'json',
success: function( data ) {
if ( 'success' === data.status ) {
$window.trigger( 'si.visitor-geolocated', [ data.geolocation ] );
}
}
} );
function si_geolocate_visitor() {
header( 'Content-Type: application/json' );
$geolocation = get_visitor_geolocation(); // get visitor location from the location cookie data
if ( empty( $geolocation ) ) {
$geolocation = request_visitor_geolocation(); // if the cookie is empty, ie. for the first time visit request geolocation using ipstack service.
if ( ! empty( $geolocation ) ) {
set_details( 'geolocation', 'data', $geolocation ); // save geolocation in location cookie.
}
}
if ( ! empty( $geolocation ) ) {
wp_die( wp_json_encode( array(
'status' => 'success',
'geolocation' => $geolocation
) ) );
}
wp_die( wp_json_encode( array(
'status' => 'error',
) ) );
}
I even tried removing the whole code from the si_geolocate_visitor function with just
wp_die( wp_json_encode( array(
'status' => 'success'
) ) );
but this too didn’t return any response.
Hi @glx77
Just checking on this. Were you able to test the code?
Thanks.
hi @fredy121 ,
i’ve no test the code yet, I’ll test it asap (may be today or monday) and I’ll get you in touch
Regards
hi @fredy121 ,
sorry for the late answer, hope you’re fine?
Can you try this code and tell me if its works:
Can you make your test ot on homepage ?
$.ajax( {
method: 'post',
url: si.ajaxUrl,
data: {
'action': 'si_geolocate_visitor'
},
dataType: 'json',
success: function( data ) {
if ( 'success' === data.status ) {
$window.trigger( 'si.visitor-geolocated', [ data.geolocation ] );
}
}
} );
function si_geolocate_visitor() {
add_filter( 'weglot_autoredirect_only_home', '__return_true' );
header( 'Content-Type: application/json' );
$geolocation = get_visitor_geolocation(); // get visitor location from the location cookie data
if ( empty( $geolocation ) ) {
$geolocation = request_visitor_geolocation(); // if the cookie is empty, ie. for the first time visit request geolocation using ipstack service.
if ( ! empty( $geolocation ) ) {
set_details( 'geolocation', 'data', $geolocation ); // save geolocation in location cookie.
}
}
if ( ! empty( $geolocation ) ) {
wp_die( wp_json_encode( array(
'status' => 'success',
'geolocation' => $geolocation
) ) );
}
wp_die( wp_json_encode( array(
'status' => 'error',
) ) );
}
Regards
Hi @glx77 ,
I am good, thanks. Hope you are fine too.
I tried the code and there is no difference. Just a reminder that the autoswitch in weglot is disabled.
To tested this further, I removed all the code from function si_geolocate_visitor() and replaced it with just a simple response
add_filter( 'weglot_autoredirect_only_home', '__return_true' );
wp_die( wp_json_encode( array(
'status' => 'success',
) ) );
Still the response is the same.