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

Problem:
I need to add a custom Currency switcher in the header of my website
Solution:
You can add the following code in the desired location (usually the header.php file):

<?php do_action('wcml_currency_switcher', array('switcher_style' => 'wcml-horizontal-list', 'format' => '%code%')); ?>

Relevant Documentation:
https://wpml.org/documentation/related-projects/woocommerce-multilingual/multi-currency-support-woocommerce/#adding-a-currency-switcher-to-the-front-end

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 rufusB 1 year, 8 months ago.

Assigned support staff: Vincenzo.

Author Posts
October 25, 2018 at 10:16 am #2849406

rufusB

Tell us what you are trying to do?
Add currency switcher to product/cart/checkout pages

Is there any documentation that you are following?
Multi-currency support for WooCommerce

What is the link to your site?
hidden link

Hi, I'm sure this is straight forward if you know how to do it but "Multi-currency support for WooCommerce" assumes a level of understanding I don't have. I just need my customers to be able to switch between three currencies and need some code or a widget, whatever, and particularly, to know exactly where to put it. Thanks

October 26, 2018 at 2:58 pm #2853416

Vincenzo
Supporter

Languages: English (English ) Italian (Italiano )

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

Hello, thank you for contacting WPML Support!

To add a currency switcher you can follow the steps outlined in these pages of our documentation:
- https://wpml.org/documentation/related-projects/woocommerce-multilingual/#multiple-currencies
- https://wpml.org/documentation/related-projects/woocommerce-multilingual/multi-currency-support-woocommerce/

Basically, you need to enable the multi-currency feature and add the needed currencies from WooCommerce -> WooCommerce Multilingual -> Multi-currency

Once the Multi-currency feature has been set up, you can add a currency switcher in the frontend by using a widget, a shortcode, or PHP code.
- https://wpml.org/documentation/related-projects/woocommerce-multilingual/multi-currency-support-woocommerce/#adding-a-currency-switcher-to-the-front-end

Please let me know if this solves the issue or if you need further details.

Thank you

October 26, 2018 at 3:46 pm #2853601

rufusB

Hi Vincenzo, thanks for getting back to me. Unfortunately it doesn't solve the problem. As I said, the article you have referred me to assumes a level of knowledge I do not have. The multi currency feature is set up, no problem, but I have no switcher. I don't know what it means to add a switcher to the frontend or theme or whatever. How do you add php code or a widget to the theme and precisely where? Thanks.

October 26, 2018 at 4:25 pm #2853656

Vincenzo
Supporter

Languages: English (English ) Italian (Italiano )

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

Hello,

1. To quickly add a currency selector to the frontend, try these steps:

- Go to Appearance -> Widgets
- Find the "Currency switcher" widget from the list on the left
- Click on it
- Select the desired Widget position (eg. Sidebar or Footer)
- Press the "Add Widget" button
- Now you can configure the Widget by pressing the "Customize the currency switcher" button.

2. To add the currency switcher on the product page, follow these steps:
- Go to WooCommerce -> WooCommerce Multilingual -> Multi-currency
- Enable the "Show a currency selector on the product page template" option
- Save

You can also manually add the Currency switcher inside the template by using hooks and shortcodes, but you need to manually edit the template files (eg. header.php file), and this requires some PHP knowledge.

In this case, I recommend contacting one of our certified partners.
Please check the link below
https://wpml.org/contractors/

Please let me know if you need further details.

Thank you

October 26, 2018 at 4:49 pm #2853757

rufusB

Hi again. Thanks for that. I have the widget set up in two areas but I now find that only one currency displays front end. On the woocommerce curency switcher set up, I am unable to edit currencies or change the default currencies of my two languages. When I save the changes, they revert to the old set up. Any ideas why this is happening?

October 26, 2018 at 4:53 pm #2853775

Vincenzo
Supporter

Languages: English (English ) Italian (Italiano )

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

Hi,

1. Can you please paste your WPML Debug information in the Debug information field?
- http://wpml.org/faq/provide-debug-information-faster-support/

2. Can you please post a screenshot of the WooCommerce -> WooCommerce Multilingual -> Multi-currency page, so I can see the configuration?

Thank you

October 26, 2018 at 5:06 pm #2853793

rufusB

Here you go, thanks again.

October 26, 2018 at 5:19 pm #2853883

Vincenzo
Supporter

Languages: English (English ) Italian (Italiano )

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

Thank you for the debug info and for the screenshots.

The Multi-currency page seems correctly set up.

1. Can you confirm that the Widgets added to the site are those added by WooCommerce Multilingual?
- Go to Appearance -> Widgets
- See the attached screenshot:

2. Try adding a widget by using these steps:
- Go to WooCommerce -> WooCommerce Multilingual -> Multi-currency
- Press the "+ Add a new currency switcher to a widget area" button
- Select the desired Widget area (first drop-down)
- Customize the currency selector (if needed)
- Save

3. If the issue is not solved yet, can you please try these steps?
- Disable the WooCommerce Multi Currency plugin
- Clear the cache (Purge), using the SG Optimizer controls
- Check the Shop page to see if the issue is solved

Thank you

October 26, 2018 at 6:44 pm #2854004

rufusB

Hi,
I can confirm 1.

I've tried adding widgets by both methods, I was only able to see them front end after Multi-Currency was disabled as per step 3. having done that and re-activated M-C, they seem permanent.

Even after Multi-currency was disabled, I am unable to edit the currencies in any way. The only change that saves is the addition or deletion of widgets. I can get up to four switchers showing in the footer but none show anywhere else. Perhaps this is due to my pages being set to "full width."

You will see from the attached screenshot, however, that there is a "GBP" in an orange box, centre right of screen. This is where I'd like a switcher as nobody will find it in the footer. Hovering over this reveals "SELECT YOUR CURRENCY GBP pound stirling" but you can't change currency. This box is activated/deactivated with Multi-Currency but I don't know how to remove it or make it show multiple currencies.

Hope that helps.

Cheers

October 27, 2018 at 11:26 am #2855042

rufusB

Hi again, I've been looking at this and here's what I've found. I think that to some extent there may be a conflict between plugins, though that doesn't explain everything.

The right hand currency selector in the above screen shot comes from "Woo Multi Currency." which is de/activated from the woocommerce multi-currency plugin. This has its own interface in the Dashboard and from this I have now got two currencies, the maximum allowed in the free version. The drop down switchers in the footer are widgets accessed from the woocommerce multilingual interface and Appearance-Widgets.

However, without the woocommerce multi-currency plugin, the widget values cannot be edited at all, it seems. With the plugin active, some values can be edited. I have managed to remove the last currency I didn't want any more, but cannot edit the location or colours of the widgets so they remain.

A workaround might be to switch my footer to the header but for this to work, I would still need to edit the currency switcher colour, as it is almost invisible at present. Presently, with "Woo Multi Currency." active, I effectively have three currencies as the castellano site is in Euros and the switcher allows a customer to change to, but not back from, USD and GBP. This isn't ideal as I can't know how it will actually work out for users.

Cheers

October 29, 2018 at 1:01 pm #2858052

Vincenzo
Supporter

Languages: English (English ) Italian (Italiano )

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

Hello,

to further debug the problem I’d like to replicate your site locally.

I would need a site snapshot if possible.
We usually recommend the free Plugin “Duplicator” for this purpose.

If you already know how Duplicator works
(https://wordpress.org/plugins/duplicator/),
please skip the following steps and just send me the archive file you downloaded.

★ Duplicator Instructions
hidden link
https://wpml.org/faq/provide-supporters-copy-site/

If the file is too large (more than 200M), please use the Duplicator file filters to remove the cache, the wp-uploads directory, the media, and the archive files.

Send me the link to the archive file (you probably want to use Google Drive, Dropbox, or similar services, as the snapshot file will be quite big)

Your next reply will be private, which means that only you and I will be able to see it and have access to it. You can paste the link to the file there. You can also share the credentials to your website. I will then download the file from the admin panel.
Once the problem is resolved I will delete the local site.

Please let me know if you need help creating the Duplicator package.

Thank you

October 30, 2018 at 12:30 pm #2861620

Vincenzo
Supporter

Languages: English (English ) Italian (Italiano )

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

Hello,

sure, you can use the two-part install.

I just need:
1. The Duplicator archive.zip file with the database
2. A zip file containing all the files on the site except the /wp-content/uploads/ folder

I am enabling a new private answer.

Thank you

November 2, 2018 at 12:46 pm #2871894

Vincenzo
Supporter

Languages: English (English ) Italian (Italiano )

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

Hello,

thank you for providing the site files.

From what I can see, you need to add a custom currency switcher.
You can do it by using the following code:

<?php do_action('wcml_currency_switcher', array('switcher_style' => 'wcml-horizontal-list', 'format' => '%code%')); ?>

As an example, in my local copy, I added a currency switcher in the top bar, right beside the Contact info. See the attached screenshot.

To do that, please follow these steps:
- copy the /wp-content/themes/nimva/functions folder and the content that you want to edit into the /nimva-child/ folder (eg. the template folder).
- Edit the /wp-content/themes/nimva-child/functions/template/contact-info.php file.
- Find lines number 11 and 12

		<?php } ?>
		<?php if($data['header_number']){ ?>

Modify them like this:

		<?php } ?>
		<li> <?php do_action('wcml_currency_switcher', array('switcher_style' => 'wcml-horizontal-list', 'format' => '%code%')); ?> </li>
		<?php if($data['header_number']){ ?>

- Save

Please let me know if this solves the issue or if you need further details.

Thank you

November 3, 2018 at 12:59 pm #2873878

rufusB

Hi, many thanks, that works.

November 3, 2018 at 1:05 pm #2873879

rufusB

My issue is resolved now. Thank you!