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

Last updated by Dražen 1 year, 8 months ago.

Assisted by: Dražen.

Author Posts
July 29, 2023 at 4:42 pm #14121679

kaiC-3

Hello,

WCML is configured with location based currency changes with GBP/USD/EUR. Due to Googles Crawlers being based in the USA, they're crawling the USD pricing of our site yet we're primary GBP.

How can we ensure the google crawlers are shown only the primary currency?

July 31, 2023 at 9:07 am #14125165

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

thanks for getting back.

If you have location-based currency, and Google is using mostly USA-based crawlers, then I am afraid there is not much we can do from the WPML side, and it is expected if you are forcing USD for USA visitors.

The best I can suggest is to use currency per language, or if you are also using the browser redirect option to disable it.

- https://wpml.org/documentation/getting-started-guide/language-setup/automatic-redirect-based-on-browser-language/how-browser-language-redirect-affects-google-indexing/

Regards,
Drazen

July 31, 2023 at 9:21 am #14125211

kaiC-3

Hello,

We have removed WPML due to on-going issues and only have WCML, so cannot use per-language.

Is it not possible to have it not automatically changed and to only be enabled via the toggles/dropdowns widgets?

July 31, 2023 at 9:28 am #14125285

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

it is possible, but not via location-based currency, as it will always revert to the location-based settings you have set.

As a workaround, you might want to try and set the currency to show for all countries, so for example GBP > All Countries, USD > All Countries. That way it will show always GBP as default and visitors can change it via the switcher.

Let me know if it helps.

Regards,
Drazen

July 31, 2023 at 9:30 am #14125297

kaiC-3

Hello,

We have that already but it still changes via location despite all currencies being available to all countries. It seems to be built into the WCML as we've not set that up.

July 31, 2023 at 9:31 am #14125339

kaiC-3

For reference WCML said it may be possible these filters, is that the case and what could be used?

https://wordpress.org/support/topic/currency-auto-changing/

https://wpml.org/wcml-hook/wcml_geolocation_get_user_country/
https://wpml.org/wcml-hook/wcml_user_store_strategy/

July 31, 2023 at 9:39 am #14125367

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

thanks for getting back and sharing that ticket.

I see my colleague already opened an internal ticket, Let me check on it for feedback and any suggestions from devs and I will get back to you.

Regards,
Drazen

August 1, 2023 at 10:43 pm #14138067

kaiC-3

Hello,

We are due to test the following filters to see if we can use that resolves the issue.

add_filter( 'wcml_geolocation_get_user_country', function( $userCountry ) {
if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'Googlebot' ) !== false ) {
return 'GB'; // GB country code or another country code that allows GBP currency.
}

return $userCountry;
} );

add_filter( 'wcml_client_currency', function( $currency ) {
if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'Googlebot' ) !== false ) {
return 'GBP';
}

return $currency;
} );

I have however found another workaround similar to the above, using Cloudflares transformation rules. In summary, the HTTP Response header rule follows these steps (Similar to the above filters)

Firstly, the following filter needs to be applied for WCML to use cookies:

add_filter ('wcml_user_store_strategy', function($strategy, $key) {
return'cookie';
}, 10, 2);

Then create the following Cloudflare Transformation Rule (HTTP Response Header Modification Rule).

If incoming requests match
1. Country = United States
AND
2. User Agent 'Contains' Googlebot
AND
3. Cookie 'Does not Contain' wcml_client_currency

Then

Add 'Set-Cookie' = wcml_client_currency=GBP

Step 3 stops every single request adding a wcml_client_currency cookie, therefore adding it only once and not repeatedly.

Cloudflare.jpg
August 2, 2023 at 6:35 am #14139153

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

great, thanks for the update, glad to hear you found a workaround for your case.

Regards,
Drazen

August 4, 2023 at 8:40 pm #14157151

kaiC-3

Hello,

We've noticed inconsistencies with the cloudflare workaround, have tried your code but doesn't seem to make any difference when using googles link inspection. prices are still showing in USD.

August 7, 2023 at 6:34 am #14161193

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

thanks for getting back.

The shared code should work if you have set the correct HTTP_USER_AGENT. As I mentioned it is just an example code, you should check further which bots are crawling your website, and for the one you wish set the correct code. It could be a Google mobile bot, or some other also. You can then use crawler tools to check and confirm further on this.

I will update you when I have more news from our side.

Regards,
Drazen

August 10, 2023 at 9:12 am #14180661

kaiC-3

Hello,

I adapted the code to the following, so any google bot should exclude it.

add_filter( 'wcml_client_currency', function( $currency ) {
if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'Google' ) !== false ) {
return 'GBP';
}

return $currency;
} );

Even using this and with a cookie being manually set via Cloudflare to GBP by default, cached pages are showing as USD or even EUR on first load despite being in the UK.

So this issue seems to be litespeed cache related, as it's caching non-default currencies and serving them. Geolocate after load is then changing back to the default currency.

August 10, 2023 at 9:19 am #14180677

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

thanks for getting back.

Yes, that seems as somehow expected as there can be issues with caching plugins and currency changes:

- https://wpml.org/errata/caching-plugins-may-cause-issues-with-wcml-multi-currency-settings/

We have some workaround and solutions for the Litespeed cache that you can try, but can you please open a new ticket we will check it out further and provide a workaround for you to test. Since we keep the ticket clear on topic and 1 issue, this one is already escalated.

Related ticket:
- https://wpml.org/forums/topic/currency-needs-to-be-changed-twice/

Regards,
Drazen