In this tutorial i want to show you how easily you can create currency selection popup window that will appear for your shop guests on their first page visit in your store (no matter what page they will open - popup will appear). This popup will obligue them to select currency. Only in that way they will be able to close modal window. Whole guide is based on our PrestaShop responsive popup pro module. Currency selection will look like on the image below.
How to create popup with currency selection
As i already mentioned, we have to install PrestaShop popup addon . We will use it to create popup that will appear for:
- everyone who will visit your shop for the first time
- everywhere, no matter what page customer will open - module will spawn this popup
- only one time, module will not spawn popup again
- customer will be obligue to select currency to close the popup
Let's open module configuration page, and go to "add new popup" section. Fill popup creation form with these informations:
Name | Currency selection (in fact you can use own, it appears only in back office) |
Active | Yes |
Test mode | No |
Display popup again after: | 36000000 |
PopUp border | 10 |
PopUp border color | EEF5DB |
PopUp background (window) | EEF5DB |
PopUp overlay color (background) | 000000 |
PopUp overlay opacity | 0.9 |
Disable default "close button" | YES |
Disable "click anywhere" to close | YES |
Appearance delay | 0 |
Popup width | 460 |
Popup height | (leave it blank, popup height will fit to its contents) |
The rest of the settings are related to visibility of the popup on selected pages etc. Don't use these options because we want to dispaly popup anywhere - no matter what page customer will open for its first shop page visit. That;s akk ub case related to popup appearance settings. Now it's time for the most important part related to contents of popup window.
Currency selection form in popup
To create selection form we must know how many currencies we have in our shop and what is the ID of each currency that we have in our store. To check these informations go to localization > currencies section in your shop back office. You can find out there list of the currencies you have with their id numbers (it's important to know ID!)
How to get currency ID in PrestaShop
Screenshot above shows localization > currencies section in PrestaShop 1.6, if you are on PrestaShop 1.7 you need to go to international > localization > currencies section and open currency page, id of currency will be visible in address bar, like on this screenshot
Based on these informations we have to create proper currency selection code. For example, if we have 2 currencies: Pound (ID:1), Złoty (ID:2) we have to create code like this:
PrestaShop 1.6.x + PrestaShop 1.7.x
<li onclick="setCurrency(1); $.closeOverlay();"><a rel="nofollow" title="Pound (GBP)">(GBP)<br />Pound</a></li> <li onclick="setCurrency(2); $.closeOverlay();"><a rel="nofollow" title="Złoty (PLN)">(PLN) <br />Złoty</a></li>
Let me explain what the most important part of code mean.
onclick="" | Code inside "" will be called right after we will click on currency button |
setCurrency(1); | here is an ID numer of currency for button. Customer will switch currency to this one after click on button |
So as you can see, we have to customize code to meet our shop configuration. We have to change setCurrency() param and currency name in the <li> elements. You can create as much buttons as you want. So - in that way - you can display each currency button.
The full code of the currency selection looks like:
<h2 style="text-align: center;">Select your currency</h2> <ul class="popupcurrencies"> <li onclick="setCurrency(1); $.closeOverlay();"><a rel="nofollow" title="Pound (GBP)">(GBP)<br />Pound</a></li> <li onclick="setCurrency(2); $.closeOverlay();"><a rel="nofollow" title="Złoty (PLN)">(PLN) <br />Złoty</a></li> <li onclick="setCurrency(3); $.closeOverlay();"><a rel="nofollow" title="Euro (EUR)">(EUR) <br />Euro</a></li> <li onclick="setCurrency(4); $.closeOverlay();"><a rel="nofollow" title="Dollar (USD)">(USD) <br />Dollar</a></li> </ul> <style> .popupcurrencies { list-style:none; margin:auto; display:block; min-width:450px; clear:both; overflow:hidden; } .popupcurrencies li a { display:inline-block; background: #FE5F55; color:#F0B67F; font-size:14px; font-weight:bold; text-align:center; padding:20px; border-radius:4px; width:100px; float:left; margin:5px; cursor:pointer; } .popupcurrencies li a:hover { background:#FF8077; } </style>
If you are on PrestaShop 1.7.x
You need to add additional contents to the popup. Paste this javascript code right below the contents of popup.
<script> function setCurrency(idc) { location.href = '?SubmitCurrency=1&id_currency='+idc; } </script>
You just have copy this code and paste it to "desktop view" "mobile view" and "tablet view" textboxes on module configuration page.
don't forget to customize setCurrency() with ID numebrs of your currencies, and don't forget to change currencies names.