Jump to content

About Checkout Currencies


Recommended Posts

20 hours ago, Safir Hosting said:

I am trying to display a secondary currency information on checkout sidebar. I digged viewcart.tpl but found nothing. I tried to explain with attached screenshot.

you're in the right template (for that screenshot), but WHMCS will only give you the total in the current currency - it won't have access to the totals in other currencies or their exchange rates with the current currency.

what you would need to do is write a hook to either get the exchange rate for the current currency to your secondary currency (Turkish Lira I assume), return it to the template and then modify the template to perform the calculation (e.g total * exchange rate), or you do the calculation in the hook too, and return the result to the template... off-hand, I can think of 3 ways to do this, 2 of which involve a hook and editing the template; the third should just require a hook.

an example hook to get an exchange rate is shown in the thread below...

though in your case it would be a ClientAreaPageCart hook. and looking at the site, it only uses 2 currencies, which simplifies things a little.

Link to comment
Share on other sites

22 hours ago, Safir Hosting said:

but how can i edit the tpl for showing it there?

upon further reflection, to do it as per your screenshot, I think you would have to edit the template - you would still need a hook to pass the exchange rate to the template though or perform the calculation(s)

if you could live with the display below, then you should only need a hook and no need to even edit the template.

wZMvPti.png

Link to comment
Share on other sites

1 minute ago, Safir Hosting said:

Hello Brian, I cannot see the display.

https://i.imgur.com/wZMvPti.png

2 minutes ago, Safir Hosting said:

Also i tried the hook you quoted above and seems it's not working.

the hook that I linked to does nothing visual, e.g there's nothing to see or outputted, it's just getting a value from the database and making it available to the template for later use.

Link to comment
Share on other sites

15 hours ago, Safir Hosting said:

How can i edit the template for secondary currency like the screenshot you sent?

the output shown in that screenshot was generated using an action hook with no template edits at all.

what should happen if someone buys a product priced in TL? should it show a USD price too or only TL ?

Link to comment
Share on other sites

1 hour ago, Safir Hosting said:

Ok, I got what you mean, where is that action hook?

they have to be custom written - unless they have been published here, or elsewhere,  previously.

check your Private Messaging to download the hook.

1 hour ago, Safir Hosting said:

Or how can i write one?

you would really need PHP experience to do that, along with knowledge of the database and some WHMCS functions... to get "an" exchange rate is simple enough and is not a million miles away from the thread link I previously gave.

btw, assuming you had a basic hook that passed exchange rates to the template, and wanted to do this in the template using that hook, then to just update only cycle would require...

<span id="recurringMonthly" {if !$totalrecurringmonthly}style="display:none;"{/if}>
    <span class="cost">{$totalrecurringmonthly} (₺{($totalrecurringmonthly->toNumeric()*$exchangerate)|string_format:"%.2f"} TL)</span> {$LANG.orderpaymenttermmonthly}<br />
</span> 

but don't bother trying that as it wouldn't work without a hook... plus you'd have to update the other 5 recurring cycles in a similar way.... and it would then need many additional IF statements based on how the output is supposed to react to different currencies... I had a quick look at this on Sunday and it would be far more complicated to do this in the template (and even longer to explain) than it would as a hook - and it takes 60 lines of code for the entire hook solution.

1 hour ago, Safir Hosting said:

How can i apply it?

you would upload it to the /includes/hooks folder and it should work straight away.

the hook is currently designed to output alternate total recurring pricing in the Order Summary part of viewcart, using the rules that...

  • if the item(s) in the cart is/are in your default currency (USD I assume), then it will also show the price in your alternate currency (TRY).
  • if the item(s) in the cart is/are in your alternate currency (TRY I assume), then it will also show the price in your default currency (USD).
  • if the item(s) in the cart is/are in another currency (e.g EUR), then it will also show the price in your default currency (USD).

I know you only have 2 currencies in your WHMCS install, so that third option should be irrelevant for now.

Link to comment
Share on other sites

12 minutes ago, Safir Hosting said:

It Seems only hook itself worked great, this works for us.

i'm glad it worked for you. 🙂

12 minutes ago, Safir Hosting said:

Other way when i edited viewcart.tpl it thrown error Ooops

you couldn't/shouldn't use both together - the Smarty code is posted there for others who want to do this in the template in the future and have a relevant hook... you will never (at least until WHMCS change the cart!) need to edit the template - the hook will do everything.

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