Safir Hosting Posted January 2, 2020 Share Posted January 2, 2020 Hello All, 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. Regards 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 3, 2020 Share Posted January 3, 2020 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. 0 Quote Link to comment Share on other sites More sharing options...
Safir Hosting Posted January 3, 2020 Author Share Posted January 3, 2020 Hello Brian, Thank you for your reply, I already edited Currency Exchange Rates from Setup > Currencies, Also will try your hook, but how can i edit the tpl for showing it there? Actually i am a bit lack of php lang. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 4, 2020 Share Posted January 4, 2020 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. 0 Quote Link to comment Share on other sites More sharing options...
Safir Hosting Posted January 4, 2020 Author Share Posted January 4, 2020 Hello Brian, I cannot see the display. Also i tried the hook you quoted above and seems it's not working. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 4, 2020 Share Posted January 4, 2020 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. 0 Quote Link to comment Share on other sites More sharing options...
Safir Hosting Posted January 4, 2020 Author Share Posted January 4, 2020 Hello Brian, The display may be fine for us, How can i edit the template for secondary currency like the screenshot you sent? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 5, 2020 Share Posted January 5, 2020 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 ? 1 Quote Link to comment Share on other sites More sharing options...
Safir Hosting Posted January 6, 2020 Author Share Posted January 6, 2020 Hello Brian, Ok, I got what you mean, where is that action hook? Or how can i write one? How can i apply it? Eren 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 6, 2020 Share Posted January 6, 2020 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. 1 Quote Link to comment Share on other sites More sharing options...
Safir Hosting Posted January 9, 2020 Author Share Posted January 9, 2020 Yes i will have only two currencies one is TRY and one is USD i will try what you explained. Very appreciate. Will update you soon. 0 Quote Link to comment Share on other sites More sharing options...
Safir Hosting Posted January 9, 2020 Author Share Posted January 9, 2020 (edited) It Seems only hook itself worked great, this works for us. Other way when i edited viewcart.tpl it thrown error Ooops 🙂 Edited January 9, 2020 by Safir Hosting Status Change 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 9, 2020 Share Posted January 9, 2020 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. 1 Quote Link to comment Share on other sites More sharing options...
Safir Hosting Posted January 9, 2020 Author Share Posted January 9, 2020 Thank you for all your effort, patience and support. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.