Skip Navigation

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 10 replies, has 2 voices.

Last updated by Pierre 1 year, 11 months ago.

Author Posts
May 13, 2022 at 6:15 pm #11219251

thibaultG

Hi,

Since the last update of WCML to latest version, I noticed a change of behavior during the checkout process.

Before:
- The currency was set based of the billing country of the customer. (Regardless of the WCML settings)

After update:
- The currency stay the same and is not changed. The currency is defined based of WCML settings. Either Geolocation or Site language.

Can you please confirm with the devs?

Thank you, Thibault

May 13, 2022 at 7:00 pm #11219365

Pierre
Supporter

Languages: English (English ) French (Français ) Portuguese (Brazil) (Português )

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

Hi Thibault,

Indeed, the behavior has slightly changed because we fixed some bugs (the previous behavior was buggy) and this is all under the change log entry "Refactored the client currency resolution logic to fix a number of bugs and performance hits".

So now, the selected currency on the checkout page respects the WCML settings once the client started filling his address, that is:
- If the current currency (selected before the checkout) is still allowed for the billing address, nothing changes.
- Otherwise, the first allowed currency for the billing address will be selected (forced).

Note that you change also adjust this behavior with the filter "wcml_geolocation_get_user_country" (https://wpml.org/wcml-hook/wcml_geolocation_get_user_country/).

Thanks,
Pierre

May 13, 2022 at 7:04 pm #11219367

thibaultG

Thanks for the clarification and quick reply.

- How do I add the currency switcher in the checkout page?

Thank you

May 13, 2022 at 7:10 pm #11219373

Pierre
Supporter

Languages: English (English ) French (Français ) Portuguese (Brazil) (Português )

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

In the multicurrency settings (at the bottom), you can add a currency switcher widget to a sidebar (and you should also be able to do that from the widgets menu).

See the doc page => https://wpml.org/documentation/related-projects/woocommerce-multilingual/multi-currency-support-woocommerce/#adding-a-currency-switcher-to-the-front-end

Thanks!

May 13, 2022 at 7:15 pm #11219397

thibaultG

I don't want to add it in sidebar but within the checkout page, right here: hidden link

below total amount for example

May 13, 2022 at 7:19 pm #11219401

thibaultG

Also I think this hook is buggy: https://wpml.org/wcml-hook/wcml_geolocation_get_user_country/

When I add it in my functions.php I get this error:

eval()'d code. Error message: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed in ....php on line 309 and exactly 2 expected in ..php : eval()'d code:2

May 13, 2022 at 7:19 pm #11219403

Pierre
Supporter

Languages: English (English ) French (Français ) Portuguese (Brazil) (Português )

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

If it's the a block-based checkout page, you can try with a shortcode ("[currency_switcher]") inside a shortcode block. Otherwise we also have a PHP action hook "wcml_currency_switcher" (that's described in the doc page).

May 13, 2022 at 7:23 pm #11219407

Pierre
Supporter

Languages: English (English ) French (Français ) Portuguese (Brazil) (Português )

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

I believe there's a glitch in our hook documentation (missing the right argument number).

Try that instead:

// Always use the shipping address if it's available
add_filter( 'wcml_geolocation_get_user_country', function( $userCountry, $allCountries ) {
    return ! empty( $allCountries['shipping'] ) ? $allCountries['shipping'] : $userCountry;
}, 10, 2 );
May 13, 2022 at 7:30 pm #11219435

thibaultG

Thank you I just tested the snippet (changed with billing instead of shipping) but it doesn't work. The currency stays the same. Nothing else.

Can you please try in your local environement?

Thank you

May 13, 2022 at 7:32 pm #11219443

thibaultG

Here a video: hidden link
It just add the VAT when switching to France but currency stays in $ USD. Same behavior without the snippet.

that's my currency settings: hidden link

May 13, 2022 at 7:52 pm #11219519

Pierre
Supporter

Languages: English (English ) French (Français ) Portuguese (Brazil) (Português )

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

Looking again at your screencast and settings screenshot, I think this behavior is actually expected. Since US Dollars are allowed for all countries, if it was already selected before, the checkout will not change it.

The topic ‘[Closed] WCML Currency logic on checkout changed?’ is closed to new replies.