I have a ajax script that will take a value from a select from on onchange. This works well, and with console.log I can see the correct value. My select form triggers a reload, and I see the value in console before the page reloads.
I want to use this value to set a backend language for WPML, but unsure how to use the value.
PHP
function my_action( ) {
$dropdown_shop_order_language = $_POST['dropdown_shop_order_language'];
echo json_encode($dropdown_shop_order_language);
wp_die();
}
add_action('wp_ajax_my_action', 'my_action');
add_action('wp_ajax_nopriv_my_action', 'my_action');
This will give me a value of de
, en
or nl
Example of function to change language:
add_action('wp_loaded', 'my_icl_set_current_language');
function my_icl_set_current_language() {
global $sitepress;
$sitepress->switch_lang('de');
}
something like this is what Im after:
$sitepress->switch_lang($dropdown_shop_order_language);
Whats the best approach here?
This doesnt work:
add_action('wp_loaded', 'my_icl_set_current_language');
function my_icl_set_current_language() {
global $sitepress;
$sitepress->switch_lang($dropdown_shop_order_language);
}
global $sitepress;
. If that doesn't work then the issue is probably specific to WPML.echo json_encode($dropdown_shop_order_language);
is giving the correct value, then you're passing the value correctly. How are you trying to use it? Please include the full code you're trying.