Please make sure to update to WPML 4.3.5 and check our list of Known Issues before reporting

Hi, Amit here, I am the WPML Support Manager, our current ticket queue is high, update your WPML plugins and make sure you meet the minimal requirements for running WPML before reporting an issue please - many tickets are resolved doing that

Please look at our updated list of Known Issues and you can also use our support search to find helpful information and of course review our documentation before opening a ticket.

If you do need to open a ticket please make sure to provide us with all the needed information as described in this page

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 8 replies, has 4 voices.

Last updated by Carl 4 years, 10 months ago.

Assigned support staff: Bruno.

Author Posts
February 4, 2015 at 5:08 pm #554647

michaK

I have a language which contains multiple currencies.

Is there the possibility to set the loading language with a URL-Parameter?

Like: hidden link

thanks for your ideas in this topic!

February 4, 2015 at 8:59 pm #554791

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

You can use the function below. Just add this function in the functions.php file and then try to change the currency at the URL:

add_action( 'wcml_client_currency', 'currency' );
function currency( $current_currency ) {

	$currency = isset( $_GET['currency'] ) ? esc_attr( $_GET['currency'] ) : $current_currency;

	return strtoupper( $currency );
}

hidden link

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Thank you.

February 4, 2015 at 10:58 pm #554842

michaK

Hi Bruno

Thanks a lot. Works fine.
But just as long as I stay on the page with the parameter. Can I set the language just like when changeing in the currency-widget so it stays even when changing product or page?

February 5, 2015 at 12:22 pm #555170

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Please, try this one:

add_action( 'wcml_client_currency', 'currency' );
function currency( $current_currency ) {
	global $woocommerce,$sitepress;

	$currency = isset( $_GET['currency'] ) ? esc_attr( $_GET['currency'] ) : $current_currency;
	$currency = strtoupper( $currency );

	$woocommerce->session->set('client_currency', $currency);    

	return $currency;
}

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Thank you.

February 5, 2015 at 12:28 pm #555173

michaK

Perfect! Thanks Bruno. I'm sure this will help a lot of other users!

February 9, 2015 at 7:51 am #556797

michaK

Hi bruno

I hope you will read this. The solution with the function worked fine to me until I updated to Version 3.5.1 of Woo Multilingual. (before I used the beta version as i needed the currency switcher widget). Has there something changed in the currency-handling?

Now I can load a product with the currency set in the url but when I change to another product or category, the currency is set back to the default of the language.

thanks Micha

January 29, 2017 at 12:42 pm #1193102

marcusL-8

Hey Bruno awesome function! Works like a charm! How ever after i added the script i get "HTTP ERROR 500" when i am browsing inside wp-admin.

Is there any way of fixing this?

August 30, 2018 at 3:20 am #2688563

Carl

Works great on frontend, but breaks wp-admin, error 500. Any solution? Would really appreciate help with this one!

August 30, 2018 at 6:26 am #2688667

Carl

This seems to be working for now.

add_action( 'wcml_client_currency', 'currency' );
function currency( $current_currency ) {

	if( !is_admin() ) {

		global $woocommerce;
		global $sitepress;

		$currency = isset( $_GET['currency'] ) ? esc_attr( $_GET['currency'] ) : $current_currency;
		$currency = strtoupper( $currency );

		$woocommerce->session->set('client_currency', $currency);

		return $currency;

	}

}