Site icon Hip-Hop Website Design and Development

Use worth from Ajax name in PHP perform

I’ve a ajax script that may take a price from a choose from on onchange. This works effectively, and with console.log I can see the right worth. My choose kind triggers a reload, and I see the worth in console earlier than the web page reloads.

I need to use this worth to set a backend language for WPML, however not sure how you can use the worth.

PHP

perform 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 may give me a price of de, en or nl

Instance of perform to vary language:

add_action('wp_loaded', 'my_icl_set_current_language'); 
perform my_icl_set_current_language() {
    world $sitepress;
    $sitepress->switch_lang('de');
}

one thing like that is what Im after:

 $sitepress->switch_lang($dropdown_shop_order_language);

Whats the perfect strategy right here?

This doesnt work:

add_action('wp_loaded', 'my_icl_set_current_language'); 
perform my_icl_set_current_language() {
    world $sitepress;
    $sitepress->switch_lang($dropdown_shop_order_language);
}