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.

Our next available supporter will start replying to tickets in about 0.24 hours from now. Thank you for your understanding.

This topic contains 5 replies, has 4 voices.

Last updated by kevinK-12 4 years, 1 month ago.

Assigned support staff: Bruno.

Author Posts
August 28, 2015 at 11:12 am #692147

shirleyZ

I am trying to: Change what currency my site is displayed in via url suffix like ?price=USD or similar

Instead, I got: not that. I was wondering if currency change via url was a feature or not.

The reason I am asking is because google data feeds requires it to land on a page that displays the currency for the feed it's targeting (EG Australia = AUD, US = USD). So I need a url that can land on a page that has the USD pricing, and another url that can land on a page that has AUD pricing.

Thanks

August 28, 2015 at 11:08 pm #692660

Bruno
Supporter

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

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

You should use custom code to it.

Please add that custom code in the functions.php file of your theme:

add_action( 'wcml_client_currency', 'currency' );
function currency( $current_currency ) {
    global $woocommerce,$sitepress;
 
    $currency = isset( $_GET['price'] ) ? esc_attr( $_GET['price'] ) : $current_currency;
    $currency = strtoupper( $currency );
 
    $woocommerce->session->set('client_currency', $currency);    
 
    return $currency;
}

* Note that you must configure the currencies before. For this, you can follow the steps of our documentation: https://wpml.org/documentation/related-projects/woocommerce-multilingual/multi-currency-support-woocommerce/

Then you can access the URL of your website like this: hidden link

This will set the cookie to use the selected 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.

August 30, 2015 at 6:22 am #692953

shirleyZ

Thank you! Works perfectly (:

May 22, 2017 at 11:22 pm #1282168

guillaumeP-15

Hi Bruno,
(All WP and plugins updated, no pending updates).
We tried your code and it works fine with the direct URL/currency, we can load the pages but...when we then login to our WP admin again we can see the dashboard and any other click will bring us to a blank page (like if there is a path issue or something else). So we had to remove the code for now. This direct URL is very important to us. Any idea?

July 22, 2019 at 9:17 am #4255249

kevinK-12

Dear Bruno, I have the same issue as guillaumeP-15. The currency switch works but I can no longer access the /wp-admin backend.

July 23, 2019 at 9:40 am #4264655

kevinK-12

I found a solution by excluding the admin and changing the add_action to add_filter as add_action is no longer in use.

add_filter( 'wcml_client_currency', 'modify_client_currency', 10, 1 );

function modify_client_currency( $current_currency ) {
	if( !is_admin() ){
	    global $woocommerce;

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

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

	    return $currency;
      }
}