The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

Change currency based on shipping country

zlbzlb Member
The store I'm working on needs to change what currency the order is charged in based on the shipping address country.
My current strategy is to display a message to the customer if they change the shipping country to one with a different currency letting them know that they will be charged in a different currency. The message will have a link to checkout with the correct prices and the correct local set.
My questions:
Is there a different approach you would suggest?
What javascript event on the checkout page should I use for checking for shipping address country changes?
I am planning to follow the pre-populating checkout fields dirrections from here to make sure that any email/address info entered by the customer transfers over. Is there a better way to do that?
  • fc_adamfc_adam FoxyCart Team
    edited March 2019

    Good question. While it is possible to change the currency of the cart, doing so will also clear out any products currently in the cart.

    With that in mind, we generally recommend that you provide a currency selection as part of your website, so that the customer is able to make the selection at the start of their purchasing experience.

    You mentioned that your approach would include a "link to the checkout with the correct prices and the correct local set". Assuming that your link re-adds any products the customer has already added, but in the new currency, that approach could work. Do you know how you'd get the correct pricing from the checkout to achieve that?

    In terms of the event on the checkout to hook into, the customer-address-update event would be your best bet. It's triggered when a completed address is entered, so you can detect changes made to the address. If you specifically just want to detect changes to the country, you could hook into a change event on the country field too.

    You mentioned about using pre-population to keep any information the customer has already entered - while that approach would be ok, it wouldn't maintain a customers logged in status for example, so wouldn't necessarily be a perfect approach. If you do already have the correct pricing for all of the products in the customers cart, instead of needing to re-direct the customer, you could perform the requests in the background on the checkout using JSONP. That way, the customer wouldn't leave the checkout, meaning any information already entered would persist, but you would still be able to update the customers cart.

    This approach would be a bit advanced, you would probably want to prevent the customer from interacting with the form while you make the updates (to ensure the session doesn't get messy with multiple changes while the requests are happening), and also re-rendering the checkout once completed to ensure the updated cart is displayed. That said, it should be possible though as an approach you could take.

    All of that said - having the currency selection on your website as an initial decision the customer makes, rather than setting it later on based on the country, would be a much easier approach if it would work. Let us know if you need any more specific details on the alternate approaches though.
  • zlbzlb Member
    Hi @fc_adam ,
    Completely agree and understand that having the currency correct from the start is the best solution. Currently we use IP geolocation to determine what price the customer sees on our website. Because we expect the vast majority of customers to be shipping to the same country that they're in there really won't be many that change at checkout. Also it's a Europe only web-shop so the only countries that we're shipping to that aren't Euro are Sweden and UK (depending on brexit of course).

    Correct the link would re-add the products. The easiest approach I can think of for getting the correct prices would be to have the prices in the two other currencies as hidden attributes of each product.

    If we could update the prices in the background that would be preferable. Can you give me a little more information on how that would work?

  • fc_adamfc_adam FoxyCart Team

    Thanks for the additional details there!

    For adding products in the background, that would be a JSONP request from the cart. You can see details on that on our wiki here: You'd need to loop through each of the items in the cart (via FC.json.items) and create an add to cart which would re-create the customers cart in their new locale. Passing through the different currencies as product options would definitely be a nice approach there, good idea. If you haven't already seen it, you can also hide options from being seen by the customer from the "configuration" section of the admin, specifically the option labelled "Customise cart display".

    I mentioned it above too, but to reiterate, I'd suggest also preventing the customer from interacting with the page while the cart is being updated. That way, it will minimise the potential for the cart to end up in an unexpected state if the customer makes multiple changes to the country while the requests are still active. You could do that by putting a semi-transparent panel over the page while it's loading, with a note displayed that the cart is being updated with a new currency for the country they've selected.
  • zlbzlb Member
    Thanks! That seams to be working very well.
    Now I just need to see if any of my coworkers can break it...
Sign In or Register to comment.