Jump to content

currency selector on header.tpl


Thembi

Recommended Posts

I would like to have the functionality to change currency when a user is logged in or not logged in and i would like it to be displayed in the header.tpl .

The functionality is already on domainchecker problem is thye form is submitting to domain checker and i want to remain to the same page ... can someone please help

Link to comment
Share on other sites

I would like to have the functionality to change currency when a user is logged in or not logged in and i would like it to be displayed in the header.tpl .

it's worth remembering that when a client is logged in, and assuming they have made a previous order with you, they cannot change their currency - the option to do so is removed from the cart and/or domainchecker - clients cannot order in multiple currencies.

 

The functionality is already on domainchecker problem is the form is submitting to domain checker and i want to remain to the same page ... can someone please help

are you suggesting that you want to add a currency dropdown to the navbar ? :?:

 

njkDwQE.png

 

if so, you'd need to use an action hook to do that... and disable it when a client is logged in.

Link to comment
Share on other sites

correct brian that`s exacly what i want to do so that my clients can change currency any time. and i want when a currency is selected from the drop down menu the whole site must change its currency to the one selected ...

 

can you help me with that action hook brian? :)

Link to comment
Share on other sites

Hi,

 

correct brian that`s exacly what i want to do so that my clients can change currency any time. and i want when a currency is selected from the drop down menu the whole site must change its currency to the one selected ...

for the avoidance of any confusion with this, I should probably expand on the first sentence of my previous reply.

 

visitors to your website, who are NOT existing clients (e.g they haven't registered or have previous orders with you), CAN change their currency to whatever your website allows - that's absolutely fine. :)

 

however, as soon as they have registered as a client, they CANNOT change their currency - when they're logged into the client area, they will only be able see pricing in THEIR currency... WHMCS is coded to prevent them from changing currency, so they'd be unable to change it - even via a clever hook in the navbar!

 

if the client has registered, but has NOT made any orders with you, then you can change their currency via the admin area - but if they have made orders, then you should NEVER change their currency... if they need to make an order in another currency, they'd need to create a new account.

 

in WHMCS, the currency is assigned to the client, not to orders, invoices etc - e.g., when WHMCS takes an order for a product with a value of $100, it is stored in the database as "100.00" - no currency settings are stored with the order... when it generates the invoice/emails etc, it uses that stored order value and wraps the client's currency settings around it (i.e adds $ and/or USD)... so if the client has existing orders in USD, and then you later change their currency setting to EUR, the stored order and invoice values would become meaningless (from a financial view) and causes a whole world of pain for you and the client! :cry:

 

can you help me with that action hook brian? :)

hopefully, you now understand that existing logged in CLIENTS cannot change their currency - so they wouldn't even see the option... and even if they could see it, it wouldn't work for them anyway. :idea:

 

also, where visitors might need to be able to change currency, e.g., cart and domainchecker, there is already an existing method - domainchecker uses flags, cart will either use flags or a dropdown (depending on your template) - so is there any need for a currency changer in the navbar? outside of those pages, i'm not sure the option would be required. :?:

 

however, the above screenshot is taken from an actual hook I quickly wrote (less than 5 mins) to answer your question - it works fine, except if you try to change currency during the middle of the order process - the navbar doesn't know where you are in the process and so returns you to the beginning... perhaps that's why WHMCS never added the currency option to the navbar themselves! :lol:

Edited by brian!
Link to comment
Share on other sites

Ohw i hear you brian .. for my site visitors to be able to view prices in different currency i think it will be a very nice feature .

i want something like this in heaader.tpl

 

{if "not logged in"}

then display currency selection

{/if}

i am advertising some tld`s on my landing page that`s why i think it would be best to have the currency selector only when a client is still a visitor.

if you could share your action hook code and how you use it in the heaader.tpl that would be awesome.

Link to comment
Share on other sites

Hi,

 

i want something like this in heaader.tpl

 

{if "not logged in"}

then display currency selection

{/if}

i am advertising some tld`s on my landing page that`s why i think it would be best to have the currency selector only when a client is still a visitor.

if you could share your action hook code and how you use it in the heaader.tpl that would be awesome.

hmm... doing it in Smarty in the header template will be easier and better than using a hook - it will correctly change the currency on any page... even half way through the order process. :idea:

 

a couple of ideas... I think the most common method would just be to use flags to represent the currencies...

 

AejSsIH.png

in the above image, the selected currency is bold and underlined - for this demo i've used old-fashioned HTML, but you can use CSS to suit your site design... also, i'm not checking if the flag image file exists, so you may want to check that there is a correct flag with a filename that uses the first two letters of the currency code - most major currencies should be there...

 

you would need to add the following code to header.tpl - perhaps after the <!-- Shopping Cart --> block of code...

 

            <!-- Currency -->
           {if !$loggedin && count($currencies) > 1}
               <div class="pull-right nav">
                   {foreach from=$currencies item=currchoice}
                       <img src="{$BASE_PATH_IMG}/flags/{$currchoice.code|substr:0:2|strtolower}.png" class="quick-nav"> <a href="{$currentpagelinkback}currency={$currchoice.id}">{if $currency.id eq $currchoice.id}<b><u>{/if}{$currchoice.code}</b></u></a>
                   {/foreach}
               </div>
           {/if}

if you only have a few currencies, this should be fine - however, if you have a lot of currencies, you may need to find alternate methods of displaying them...

 

one might be to duplicate the way the language options are displayed...

 

pDa0m6q.png

to do this, you'd need to add the following code to header.tpl - after the <!-- Language --> block of code...

 

            {if !$loggedin && count($currencies) > 1}
               <div class="pull-right nav">
                   <a href="#" class="quick-nav" data-toggle="popover" id="currencyChooser"><i class="fa fa-usd"></i> {$LANG.choosecurrency} <span class="caret"></span></a>
                   <div id="currencyChooserContent" class="hidden">
                       <ul>
                           {foreach from=$currencies item=currchoice}
                               <li><img src="{$BASE_PATH_IMG}/flags/{$currchoice.code|substr:0:2|strtolower}.png"> <a href="{$currentpagelinkback}currency={$currchoice.id}">{if $currency.id eq $currchoice.id}<b><u>{/if}{$currchoice.code}</b></u></a></li>
                           {/foreach}
                       </ul>
                   </div>
               </div>
           {/if}

additionally, you would need to add some code to six(or custom template)/js/whmcs.js

 

    // Currency chooser popover
   jQuery('#currencyChooser').popover({
       container: 'body',
       placement: 'bottom',
       template: '<div class="popover language-popover" role="tooltip"><div class="arrow"></div><div class="popover-content"></div></div>',
       html: true,
       content: function() {
           return jQuery("#currencyChooserContent").html();
       },
   });

... or perhaps if you wanted a simpler, more elegant, popover... :)

 

7nmcmjC.png

in header.tpl...

 

            <!-- Currency -->
           {if !$loggedin && count($currencies) > 1}
               <div class="pull-right nav">
                   <a href="#" class="quick-nav" data-toggle="popover" id="currencyChooser"><i class="fa fa-usd"></i> {$LANG.choosecurrency} <span class="caret"></span></a>
                   <div id="currencyChooserContent" class="hidden">
                       {foreach from=$currencies item=currchoice}
                           <img src="{$BASE_PATH_IMG}/flags/{$currchoice.code|substr:0:2|strtolower}.png"> <a href="{$currentpagelinkback}currency={$currchoice.id}">{if $currency.id eq $currchoice.id}<u>{/if}{$currchoice.code}</u></a>
                       {/foreach}
                   </div>
               </div>
           {/if}

and then in whmcs.js...

 

    // Currency chooser popover
   jQuery('#currencyChooser').popover({
       container: 'body',
       placement: 'bottom',
       template: '<div class="popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>',
       html: true,
       content: function() {
           return jQuery("#currencyChooserContent").html();
       },
   });

hopefully, that's the sort of thing you had in mind! :idea:

Link to comment
Share on other sites

  • 3 weeks later...

Hello Brian,

 

Thanks for the tips so far.

 

This currency selector works fine on the header, but it doesn't work on my custom whmcs website template where I'm using the javascript based data feeds. Any idea how I can display the whmcs products prices on my custom theme without javascript and have this currency selector work for it?

 

Cheers!

Link to comment
Share on other sites

http://docs.whmcs.com/Data_Feeds#Product_Pricing_and_Currency

 

<script language="javascript" src="feeds/productsinfo.php?pid=1&get=price&billingcycle=monthly¤cy=2"></script>

 

Thanks for the response. I already use this. I have 2 currencies configured, but I wish to have a single currency display at a time, controlled by the currency selector on the page header.

Link to comment
Share on other sites

Yes, I have used this. but I wish to be able to use one currency at a time (I have two) and allow unregistered users switch the currency displayed on the pages by selecting their currency on the page header.

 

The page header code you wrote it working fine in the cart by the way, but does not work on the the custom whmcs theme using that javascript data feed code.

Link to comment
Share on other sites

Yes, I have used this. but I wish to be able to use one currency at a time (I have two) and allow unregistered users switch the currency displayed on the pages by selecting their currency on the page header.

 

The page header code you wrote it working fine in the cart by the way, but does not work on the the custom whmcs theme using that javascript data feed code.

Link to comment
Share on other sites

http://docs.whmcs.com/Data_Feeds#Product_Pricing_and_Currency

 

<script language="javascript" src="feeds/productsinfo.php?pid=1&get=price&billingcycle=monthly¤cy=2"></script>

 

Yes, I have used this. but I wish to be able to use one currency at a time (I have two) and allow unregistered users switch the currency displayed on the pages by selecting their currency on the page header.

 

The page header code you wrote it working fine in the cart by the way, but does not work on the the custom whmcs theme using that javascript data feed code.

Link to comment
Share on other sites

Yes, I have used this. but I wish to be able to use one currency at a time (I have two) and allow unregistered users switch the currency displayed on the pages by selecting their currency on the page header.

 

The page header code you wrote it working fine in the cart by the way, but does not work on the the custom whmcs theme using that javascript data feed code.

Link to comment
Share on other sites

Yes, I have used this. but I wish to be able to use one currency at a time (I have two) and allow unregistered users switch the currency displayed on the pages by selecting their currency on the page header.

 

The page header code you wrote it working fine in the cart by the way, but does not work on the the custom whmcs theme using that javascript data feed code.

Link to comment
Share on other sites

Yes, I have used this. but I wish to be able to use one currency at a time (I have two) and allow unregistered users switch the currency displayed on the pages by selecting their currency on the page header.

 

The page header code you wrote it working fine in the cart by the way, but does not work on the the custom whmcs theme using that javascript data feed code.

Link to comment
Share on other sites

Yes, I have used this. but I wish to be able to use one currency at a time (I have two) and allow unregistered users switch the currency displayed on the pages by selecting their currency on the page header.

 

The page header code you wrote it working fine in the cart by the way, but does not work on the the custom whmcs theme using that javascript data feed code.

Link to comment
Share on other sites

Yes, I have used this. but I wish to be able to use one currency at a time (I have two) and allow unregistered users switch the currency displayed on the pages by selecting their currency on the page header.

 

The page header code you wrote it working fine in the cart by the way, but does not work on the the custom whmcs theme using that javascript data feed code.

Link to comment
Share on other sites

  • 2 weeks later...
Thanks for the response. I already use this. I have 2 currencies configured, but I wish to have a single currency display at a time, controlled by the currency selector on the page header.

then you'd have to modify the feeds to use the current selected currency instead of specifying the currency in the link.

Link to comment
Share on other sites

then you'd have to modify the feeds to use the current selected currency instead of specifying the currency in the link.

 

Thanks Brian for the response. The forum had been messing with my replies all month long.

 

I have no idea how to do this. Is there some tutorial you could point me to, please?

 

 

Cheers!

Link to comment
Share on other sites

  • 10 months later...
  • 3 years later...
On 7/8/2016 at 11:47 AM, brian! said:

7nmcmjC.png

 

 

in header.tpl...


            <!-- Currency -->
           {if !$loggedin && count($currencies) > 1}
               <div class="pull-right nav">
                   <a href="#" class="quick-nav" data-toggle="popover" id="currencyChooser"><i class="fa fa-usd"></i> {$LANG.choosecurrency} <span class="caret"></span></a>
                   <div id="currencyChooserContent" class="hidden">
                       {foreach from=$currencies item=currchoice}
                           <img src="{$BASE_PATH_IMG}/flags/{$currchoice.code|substr:0:2|strtolower}.png"> <a href="{$currentpagelinkback}currency={$currchoice.id}">{if $currency.id eq $currchoice.id}<u>{/if}{$currchoice.code}</u></a>
                       {/foreach}
                   </div>
               </div>
           {/if}
and then in whmcs.js...

    // Currency chooser popover
   jQuery('#currencyChooser').popover({
       container: 'body',
       placement: 'bottom',
       template: '<div class="popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>',
       html: true,
       content: function() {
           return jQuery("#currencyChooserContent").html();
       },
   });
 

 

hopefully, that's the sort of thing you had in mind! :idea:

I was hoping to use this option as I am using v8.1.0 but trying this doesn't get this to display correctly is doesn't also update the prices on the pages to are there any new updates on this to be implemented please?

Edited by srwilliams86
Link to comment
Share on other sites

On 18/01/2021 at 23:38, srwilliams86 said:

I was hoping to use this option as I am using v8.1.0 but trying this doesn't get this to display correctly is doesn't also update the prices on the pages to are there any new updates on this to be implemented please?

it still works in v8.1... 🙂

432Qtjd.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated