This thread is resolved. Here is a description of the problem and solution.
Problem:
How to create a link for the WooCommerce Google Product Feed plugin to include the multi-currency support for the translated products.
Solution:
Add the following code to the functions.php file of your 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; } }
After that, if you use the parameter language URL format add a link like this to the product feed:
website.com/?lang=CODE¤cy=CUR
For the directory mode language URL format:
website.com/CODE/?currency=CUR
Replace CODE with the language code and replace CUR with the currency that you want.
Relevant Documentation:
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 14 replies, has 2 voices.
Last updated by marcelaB-4 2 years, 4 months ago.
Assisted by: Christopher Amirian.
Author | Posts |
---|---|
October 31, 2021 at 1:46 pm #9898413 | |
marcelaB-4 |
I am trying to setup Merchant Centre on Google using Woocommerce Product Feeds plugin. Three feed files are setup to differentiate language and currency. woocommerce-cs.xml - czech language and CZK prices - works fine Is there a currency marker in URL of the feed to ensure EUR prices are sent instead of CZK prices, alternatively how do I make sure the feed reflects the EUR currency? At the moment, the url of the feed is always the same with language extention only i.e. ?lang=en and ?lang=de but my website does not use url exntention for currency but widget |
November 1, 2021 at 8:24 am #9900391 | |
Christopher Amirian Supporter
Languages: English (English ) Timezone: Asia/Yerevan (GMT+04:00) |
Hi there, That is a good point, Actually, I think we never tested the feed plugin with the multi-currency feature and that might be the fact that it is not compatible with that specific feature but it needs to be tested. For now would you please test this way: - Go to "WordPress Dashboard > WPML > Languages > Language URL Format". After that please check this URL: YOURWEBSITE.com/en/?woocommerce_gpf=google See if it shows the feed with the correct currency or not. Thank you. |
November 1, 2021 at 11:01 am #9901201 | |
marcelaB-4 |
Hi Christopher, thanks for getting back to me. Before I go ahead, just to be sure... There are various websites and articles not to mention social media linked to the nayavita.com website. The links are in the current format where language is a parameter. By doing the change you suggested, does it mean these cross-links will no longer work? Because if that is the case, this cannot be the solution. Is there a way to include currency parameter just in the feed url? Thank you. Marcela |
November 1, 2021 at 12:30 pm #9901521 | |
Christopher Amirian Supporter
Languages: English (English ) Timezone: Asia/Yerevan (GMT+04:00) |
Hi Marcela, Yes this seems to be a problem as you will lose the link sharing if you change the language URL format mode. mmm..... From what I understand there is a way to force a URL parameter when it comes to the currency switcher. You need to follow sthe teps mentioned here: https://wpml.org/forums/topic/how-can-i-change-the-currency-with-url-parameter/#post-2909664 After that a URL like: hidden link will have the currency in Euro. But I am not sure if this will work when it comes to a third party plugin product feed you know. You can test that and get back to us. Thanks. |
November 1, 2021 at 1:38 pm #9901819 | |
marcelaB-4 |
Hi Christopher, I have added the code to functions.php and updated the url in Google Merchant Centre for my English and German product feeds to include the /?currency=EUR parameter. Tried to add it before the language parameter but that didnt work so popped it at the end of the url. The feed works but still pulls CZK data for both language feeds. I suggest to leave it over night as sometimes google takes a while to reflect the changes properly but for now I did try to re-process both feeds in EUR and fetch new data and still had the same error. I will check tomorrow and get back to you here once I know more. |
November 1, 2021 at 1:45 pm #9901825 | |
marcelaB-4 |
Actually: Uncaught Error: Call to a member function get() on null in wp-content/themes/porto-child/functions.php:55 |
November 1, 2021 at 1:51 pm #9901831 | |
marcelaB-4 |
And to add, I changed it back to the second php code in that forum, the error is gone but the feed is still in CZK |
November 2, 2021 at 7:46 am #9905983 | |
marcelaB-4 |
Hi Christopher, I have checked the MC and the currency parameter doesnt work. More so, it actually somehow 'negates' the language parameter too, making the feed in Czech, as opposed to English or German. Any ideas? I cannot change all permalinks as discussed before since we don't know if that will work and there are backlinks to my website and cross-links between my websites and within that would stop working. Many of which I cannot update. Thank you. Marcela Marcela |
November 2, 2021 at 8:34 am #9906251 | |
Christopher Amirian Supporter
Languages: English (English ) Timezone: Asia/Yerevan (GMT+04:00) |
Hi Marcela, Thank you for testing that method. It seems that indeed WPML does not support the multicurrency feed with the plugin in question. To test that, we will need to replicate the fact that it is not working with multicurrency and then report this to the compatibility team and wait for their answer, it might be something that can be implemented or it will need more cooperation from the plugin developer. But at the time being, I do not have another suggestion other than reporting this to the compatibility team. I created a clean installation of WordPress, WPML, and all necessary WPML add-ons. - Install the feed plugin This will help us to report the probable issue to the compatibility team and solve the possible problem faster. Thank you. |
November 2, 2021 at 8:40 am #9906377 | |
marcelaB-4 |
Hi Christopher, To replicate that, you would need to have your site linked to Google Merchant Centre, since it is there where the feed is showing up in CZK. The currency switcher widget on the site looks fine. Also, the Woocommerce product feed is a paid plugin - is that something you have available to replicate? Marcela |
November 3, 2021 at 6:38 am #9914041 | |
Christopher Amirian Supporter
Languages: English (English ) Timezone: Asia/Yerevan (GMT+04:00) |
Hi Marcela, Unfortunately, I do not have access to the plugin files. I spent more time on the issue and found this solution: https://wpml.org/forums/topic/google-product-feed-and-currency-issue/ Would you please kindly check and see if it is working on your case? Thank you. |
November 3, 2021 at 7:31 am #9914219 | |
marcelaB-4 |
Hi Christopher, Thank you for this. Once I Include this code in the functions.php, what is the url structure I need to put in the Merchant Centre feed? Remember I am already using language parameter to have feeds in different languages. Would it be: Is there anything I need to do with cache to make this work? Thank you Marcela |
November 3, 2021 at 7:09 pm #9920019 | |
marcelaB-4 |
Hi Christopher, Thanks! It seems to work now. I will check tomorrow once the Google MC feed refershes over night and applies all changes and will confirm the issue is resolved. Marcela |
November 4, 2021 at 8:36 am #9922877 | |
Christopher Amirian Supporter
Languages: English (English ) Timezone: Asia/Yerevan (GMT+04:00) |
Sure. Thanks Marcela. |