Skip Navigation

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

Problem:

The currency parameter for WooCommerce Google Product Feed and Currency is not working.

Solution:

Add the following function to the functions.php file of the theme.

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

This is a suggestion that worked in this specific case. We can not guarantee that it would work in any case.

Documentation

https://wpml.org/wcml-hook/wcml_client_currency/

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

Last updated by Itamar 4 years, 5 months ago.

Assisted by: Itamar.

Author Posts
September 6, 2020 at 11:14 am #6951729

maaykS

we are using WPML with Woocommerce and multicurrency. We are also using the Woocommerce Product Feed plugin https://woocommerce.com/products/google-product-feed/. It seems that plugin isn't compatible with WPML because it says in the documentation that you can add ¤cy=usd to the feed url to change the currency but it's not working on our website. Do you have a workaround for this?

September 7, 2020 at 2:33 pm #6958121

Itamar
Supporter

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

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

Hi.

I've checked many things regarding this issue and I'm also waiting for a response from our second tier supporters.

To check this issue I created a sandbox site and installed the Google Product Feed plugin on it. I don't have the latest versions of this plugin with me and I can not set up a Google Merchant Centre account as it is required for this plugin. So I'm not sure whether I'm testing things in the most proper way. But in any case, the currency URL parameter is not working on my test site as well. To make the currency parameter work I needed to use the following hook.
https://wpml.org/wcml-hook/wcml_client_currency/
And I added the following function to the functions.php file of the theme.

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

This makes the currency URL parameter work on the fron-end.
You can see it here.
hidden link
And if you want to check things you can access the test site by pressing this link.
hidden link

Please try this function and see if it works for you for the feed.

When I have an answer from our second tier supporters I'll update you here.

Thank you for your patience.

Regards,
Itamar.

September 7, 2020 at 6:20 pm #6959159

maaykS

Hi Itamar,

Thank you for all your help so far. I tested it and the filter is working on our website. You can see it yourself on the link I sent you before. For now this solves our problem so I am able to submit the products feeds to Google. If there is a more permanent fix for this then please let me know.

September 8, 2020 at 6:30 am #6961597

Itamar
Supporter

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

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

Great, I'm glad that it is solved now!

There is no other built-in solution in WPML to get this result.
This the reason that WPML has the API hooks.

Good luck with your web projects 🙂
Itamar.