View Full Version : Change currency dynamically from a drop down menu for an ecommerce web page
joebardy
06-16-2010, 07:39 PM
Hi there,
I am trying to find a way of changing the currency on an ecommerce web shop page by means of a drop down menu. My inspiration is this page: www.burgerplex.com/ (http://www.burgerplex.com/)
The drop down menu is located on the left above the vertical menu, and changes the item prices on the page from Euros to Dollars etc.
Does anyone know how this is acheived? I am assuming it is through PHP, or could anyone point me in the direction of some useful tutorials?
Many thanks,
Joe.
djr33
06-16-2010, 10:37 PM
The page reloads, so it looks like that is in fact processed on the server-- it's probably PHP. It's also possible to do this using Javascript (it would require that the user has Javascript and it would switch without reloading the page). You could do a combination of both (on the page use Javascript, when checking out use PHP, or whatever combination you'd like).
However, either way the setup here isn't too complex:
1. Whenever you have a price, use a variable/function rather than a text value. For example in PHP: echo moneychange(34); (Where 34 is in your base units, let's say dollars).
2. Create a function to loop through all of those to change them (most applicable in Javascript) or if you use a function like above (in PHP, maybe JS), it will automatically generate the right value when it loads. The function itself will take the base currency and input and convert it (basic math) to the stored "user currency" and output the final version. Note that you don't want to have a currency symbol in the input, but you can add one in the output.
3. You will want to track the currency so that later pages are loaded with the same one. Using $_SESSION in PHP is a good way or you can use a cookie (JS/PHP).
4. Here's the hard part: within the function mentioned in (2), you will need to get the actual exchange rates. You can of course just use numbers, but that means they won't change over time. If you want to maintain it manually, fine. If not, you will need to link it to a source for current rates, find the right one, then convert. Look around google, and if I recall correctly there was recently a thread (I think in "Looking for a script or service") asking about this [using Javascript, but it can be converted] that listed a good source.
joebardy
06-17-2010, 09:49 PM
Thank you so much for the reply, it has helped me out very much.
Many thanks!
Joe.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.