Jump to content

How to get current currency in header.tpl?


namhost

Recommended Posts

This code works fine on /cart.php

{foreach from=$currencies item=currchoice}
    <li>
        <a href="{$currentpagelinkback}currency={$currchoice.id}" class="{if $currency.id eq $currchoice.id}active{/if}">
            {$currchoice.code}
        </a>
    </li>
{/foreach}
 

But on /index.php, the "$currency" variable is empty. So this part doesnt work:

{if $currency.id eq $currchoice.id}active{/if}

Any idea why the "$currency" variable is not active on all pages? And any idea how to add it to all pages? 

Or is the current currency perhaps stored in session somewhere that I can grab it?

 

Edited by WHMCS ChrisD
Added code into code boxes
Link to comment
Share on other sites

8 minutes ago, namhost said:

Any idea why the "$currency" variable is not active on all pages?

because it's only available to the cart. 🙂

if a client is logged in, then you can find their currency - but as users cannot change their currency, that's not really relevant to your needs I think.

there are GeoIP solutions that can determine where a user is from and set a currency (if they're not logged in)...

9 minutes ago, namhost said:

And any idea how to add it to all pages?

i'm not sure why you would need to - are you intending to show pricing on a non-cart page ?

17 minutes ago, namhost said:

Or is the current currency perhaps stored in session somewhere that I can grab it?

only if the user has changed it whilst in the cart - so when they first go to the homepage, a currency will not be set - and it won't be in the session array... and just going to the cart doesn't set one (the cart defaults to using your default currency but it isn't set as such)... whilst in the cart, if they change currencies, then it will added to the session and available on all pages.

using the code i've posted previously for adding a currency to the header menu will also change the currency session value..

though that jQuery code could be added to a hook file rather than editing and minifying core files - the template edit to add the currency menu would still be required though.

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