Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:

This was an issue with the currency symbol in the mini cart widget in the header. It didn't change to the current symbol when the cart was empty.

Solution:

We checked this issue on our side and found it was not an issue with WPML or WooCommerce Multilingual & Multicurrency. It was an issue with the custom code by the user.

0% of people find this useful.

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

Last updated by Itamar 4 years ago.

Assisted by: Itamar.

Author Posts
August 23, 2020 at 10:36 am #6853485

ghadaha

i means abc.com?currency=USD

August 23, 2020 at 3:25 pm #6854911

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi.

I have the solution for how you can change the currency using a URL parameter.
Here are two options that you can use.

1. This first option is according to the example that we give in our wcml_client_currency hook here https://wpml.org/wcml-hook/wcml_client_currency/

A. Add the following code to the functions.php file of your theme.

/**
 * Add this code to the functions.php file of your theme.
 */
add_filter( 'wcml_client_currency', 'modify_client_currency', 10, 1 );
 
function modify_client_currency( $currency ) {
    if ( is_shop() ) { 
        return 'USD'; // If this is a shop page, change the front-end currency to USD 
    } else {
        return $currency;
    }
}

In this example, every time you visit the shop page of the site you will see the currency in USD. You can, of course, change the currency and the page in the function.

2. I also checked the other example from the ticket in which you shared the link with me.

https://wpml.org/forums/topic/can-i-make-the-website-display-in-a-certain-currency-via-url/#post-4264655

If you add this code then you can change the currency using a URL parameter.

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;
      }
}

For example, if the currency is USD and you add the parameter like this then it would change into EUR.
your-domain.com/?currency=EUR

Please let me know if this information is helpful to you.

Regards,
Itamar.

August 23, 2020 at 5:37 pm #6855211

ghadaha

when i am changing currency using url parameter custom code was given by you.

it was change successfully but after few sec it is change to default forced location currency using ajax. Image attached...

I am using hook wcml_client_currency

I am thinking "Store a language cookie to support language filtering for AJAX " cookies not stored by wcml_client_currency i feel..

If i m correct can you way to add cookies in hooks by custom code?

but in same page product listing of best product have correct currency.

misteva.com/ this is url

18.png
August 24, 2020 at 6:50 am #6856823

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi.

You wrote: "it was change successfully but after few sec it is change to default forced location currency using ajax. "

I was not able to replicate this problem on your site. When I force with the URL parameter to change the currency it stays like that even if I wait for a few minutes. Please see the attached screenshot.

Can you please give me the exact steps on how to replicate and see this issue on your site?

You wrote: "I am thinking "Store a language cookie to support language filtering for AJAX " cookies not stored by wcml_client_currency i feel.."

I'm not sure that this is the case. I say it because even on my local test site I was not able to replicate this problem.

You might find one of the following hooks that can are related to Ajax and currency helpful in your case.

https://wpml.org/wcml-hook/wcml_multi_currency_ajax_actions/
https://wpml.org/wcml-hook/wcml_load_multi_currency_in_ajax/
https://wpml.org/wcml-hook/wcml_switch_currency/
https://wpml.org/wcml-hook/wcml_set_client_currency/
https://wpml.org/wcml-hook/wcml_localize_woocommerce_on_ajax/

If you need more help from us, could you please share your Debug information with me?
You can read a detailed explanation about it here.
http://wpml.org/faq/provide-debug-information-faster-support
The debug info will give me a lot of information about how your site is configured and will help me understand the source of the problem.

Thanks,
Itamar.

2020-08-24_9-36-46.png
August 24, 2020 at 4:47 pm #6861745

ghadaha

Yes its first time its working fine.. if you changing again... it is not saved... i think some cookies saved or something else. You can check its not working...

August 24, 2020 at 4:48 pm #6861747

ghadaha

Also kindly try diffrent currency 4-5 currency check in same browser without deleted session or cookines

August 25, 2020 at 3:30 am #6864199

ghadaha

Also try to without login in admin in a fresh browser without any old session and old cookies..

So first time it can be set correctly. but next time it will have issue. and it will go to default to which was setting first time...

I feel we missing cookies

August 25, 2020 at 3:33 am #6864207

ghadaha

Also i have query...

I seen a function in inc/class.wcml.cart.php

public function get_cart_total_in_currency( $currency ) {

$client_currency = $this->woocommerce_wpml->multi_currency->get_client_currency();
$cart_total = 0;
$cart_items = WC()->cart->get_cart_contents();

// items total
foreach ( $cart_items as $item ) {
$item_product_id = $item['variation_id'] ?: $item['product_id'];
$cart_total += $this->woocommerce_wpml->multi_currency->prices->get_product_price_in_currency( $item_product_id, $currency ) * $item['quantity'];
}

$cart_total += $this->get_cart_shipping_in_currency( $currency );

$cart_total = $this->woocommerce_wpml->multi_currency->prices->apply_rounding_rules( $cart_total, $currency );

return $cart_total;
}

what is use of getting $client_currency parameter here?

NO where its used in function.

August 25, 2020 at 9:44 am #6866841

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

I'm sorry but I'm still missing the exact details on how to replicate the problem that you are having with the wcml_client_currency hook.

You wrote: "Also kindly try diffrent currency 4-5 currency check in same browser without deleted session or cookies"

So I tried it like this.

1. On a product page, I added the currency parameter like this.
hidden link
And then I change it also to other currencies like this.
hidden link
hidden link
hidden link
hidden link
In each time I change the currency of the parameter and press ENTER or refresh the page I get the correct currency showing. For example the DKK currency. Please see the attached screenshot.

Am I replicating the problem correctly?
If not then what are the exact steps that I need to take?

Please note that I tried the above when I was logged out.

2. You asked: "what is use of getting $client_currency parameter here?"

It is a public function. It is used in other files.

Regards,
Itamar.

2020-08-25_9-24-42.png
August 25, 2020 at 4:40 pm #6870693

ghadaha

plz see this video hidden link ... its working only first time.. when next time using dropdown url changes its not work... u can see after few sec cart content got in diffrent currency ... Also plz try on homepage also On product page in my case its not working at all.

Which browser you trying?

August 25, 2020 at 4:41 pm #6870695

ghadaha

What is your availability? its taking too long time to reply by you. can we chat some time?

August 26, 2020 at 5:50 am #6873909

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi.

I'm sorry, but the video is very shaky and gets out of focus.
It is hard for me to follow and understand what is wrong there.

But watching the video, I think that I've just realized that you are talking about an option to switch currencies. I'm talking about the option that you show in the video which comes up as a pop-up window. Please see the attached screenshot.

All the time I thought that you have some problem with the wcml_client_currency hook and the currency URL parameter.

So for me to help you better, I must understand the problem correctly.
If indeed, the problem is with the pop-up currency switcher, then please tell me what created this feature?
I ask this because this is not a feature that is built-in in WooCommerce Multilingual.
Is this the currency pop-up feature possible by another WooCommerce plugin that you added or maybe the theme that you are using?

I'll be available today until 4:15 pm GMT+3 time zone. If you want to chat, please open a chat in our forum and ask for me.

Thanks,
Itamar.

2020-08-26_8-33-16.jpg
August 26, 2020 at 12:16 pm #6877247

ghadaha

Nothing < This popup just call url with new currency

Like url.com?currency=USD or url.com/ar/?currency=USD or url.com?currency=INR

Switcher not called any ajax... just reloading url

Popup just for that... So when its reload

Currency work for few sec and just after few sec its retrieve to perivious

August 26, 2020 at 12:48 pm #6877761

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi and thanks for the extra details.

I can see now this issue on your site.

First please check that it is not a caching issue by clearing all the cache on your site and deactivating all the caching plugins. If oyu have caching also on the server please also deactivate it.

If the problem persist even when all the caching is deactivate them, I suspect that there is a collision with the theme or another plugin that might cause this problem. If possible get your site into a minimum environment. Minimum environment means switching to a default WordPress theme like Twentytwenty and no plugins activated except WPML.

You will need first to check if the problem persists when just the theme is switched to Twentytwenty (for example). If it persists then deactivate all plugins except the WPML and its add-ons and WooCommerce itself (without any of its add-ons). Then please check if the problem persists. If it does not persist so start by activating the plugins one by one and check when the problem comes back, then report to me which was the culprit plugin.

**** Important! Please make a full site backup (files and DB) before you proceed with those steps****


*** If your site is a live site you might want first to try those procedures in a staging environment or a snapshot of your site on your local server or another server. ***

Thanks,
Itamar.

August 26, 2020 at 1:07 pm #6877923

ghadaha

I have check with all non essential plugin deactivate but its preserved... will check theme also..

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.