onliner Posted March 10, 2018 Share Posted March 10, 2018 (edited) Hello, My goal is to render price in the following format: 5.95 NOT $5.95 Using the source information from https://docs.whmcs.com/classes/7.1/WHMCS/View/Formatter/Price.html and https://blog.whmcs.com/132057/customise-price-formatting-with-the-price-formatter, I'm trying to remove the prefix currency sign. In other words, I just want a numeric output. So, I'm using this in viewinvoice.tpl file: {$total->toNumeric()} But the page just goes white when trying to load. I've enabled error log but no output shows. Can someone shed some light over this? Thanks in advance! Edited March 10, 2018 by onliner Link to comment Share on other sites More sharing options...
brian! Posted March 10, 2018 Share Posted March 10, 2018 54 minutes ago, onliner said: Can someone shed some light over this? this is an unhelpful comment, but it should work! anything in the activity log ? if you have to, you could always use... {$total|replace:'$':''} 2 Link to comment Share on other sites More sharing options...
onliner Posted March 10, 2018 Author Share Posted March 10, 2018 10 minutes ago, brian! said: if you have to, you could always use... {$total|replace:'$':''} Yay! Thanks for this tip, you made my day 1 Link to comment Share on other sites More sharing options...
onliner Posted March 10, 2018 Author Share Posted March 10, 2018 Just a question regarding the prefix and suffix thing. Is there a way to just extract, or show, the currency sign, or prefix & suffix without the numeric price itself? Example: USD NOT 15.95 USD I know it sounds strange, but I need such output for a thing. Any help... Link to comment Share on other sites More sharing options...
brian! Posted March 10, 2018 Share Posted March 10, 2018 if you want to do it using the price formatter, to get the suffix alone... {$total|replace:$total->toPrefixed():''} or to get the prefix... {$total|replace:$total->toSuffixed():''} if you're on other pages, the $currency array might be available.... and certainly if the client is logged in, you will know their currency and so you could query the db for the prefix/suffix in a hook. 1 Link to comment Share on other sites More sharing options...
onliner Posted March 10, 2018 Author Share Posted March 10, 2018 Yes, this is perfect. Thanks a lot again! Link to comment Share on other sites More sharing options...
onliner Posted March 11, 2018 Author Share Posted March 11, 2018 On 2018-03-10 at 12:09 PM, brian! said: if you have to, you could always use... {$total|replace:'$':''} 1) Now, I'm in trouble, because I need to replace BOTH prefix AND suffix and just to render the numeric value. Several currencies and prefixes & suffixes. The good thing is that I know what I want to replace: Prefix '$' and '€'. Suffixes 'USD' and 'EUR. The result: 15.95 NOT $15.95 USD 2) At one spot I just need to render suffixes, without numerical values and without the prefixes. The result: EUR NOT €15.95 EUR Any idea? Thanks in advance. Link to comment Share on other sites More sharing options...
brian! Posted March 11, 2018 Share Posted March 11, 2018 45 minutes ago, onliner said: Any idea? Thanks in advance. well using toNumeric() would be the simplest way, but if that's not working and you know what you want to replace... {$total|replace:'$':''|replace:'€':''|replace:'USD':''|replace:'EUR':''} 1 Link to comment Share on other sites More sharing options...
onliner Posted March 11, 2018 Author Share Posted March 11, 2018 1 hour ago, brian! said: well using toNumeric() would be the simplest way That's the problem, when using {$total|replace:$total->toNumeric():''} then nothing happens. The price is rendered both with prefix and suffix. Not sure why 'toNumeric' doesn't work!? Link to comment Share on other sites More sharing options...
onliner Posted March 11, 2018 Author Share Posted March 11, 2018 1 hour ago, brian! said: {$total|replace:'$':''|replace:'€':''|replace:'USD':''|replace:'EUR':''} It works, perfectly! Thanks a lot. Link to comment Share on other sites More sharing options...
brian! Posted March 11, 2018 Share Posted March 11, 2018 3 hours ago, onliner said: The price is rendered both with prefix and suffix. Not sure why 'toNumeric' doesn't work!? my thought is there may be a corrupt/missing file somewhere as to why this isn't working... i'm assuming that you've added a debug to viewinvoice.tpl and checked $total is a price formatted variable ? i'm sure it should be. I seemingly don't have any invoices on my v7.1.2 dev, but the above code worked on v7.4.2 and v7.2.3 and I don't recall anything in the changelog saying price formatting was bugged in v7.1... you could try manually uploading the files from the full download version of your installed release and hoping that fixes it... otherwise, wait until you next upgrade. if you're going to do a lot of manipulating of these price formatting variables, then it's going to be easier if you can get toNumeric() working... yes you can code around without it if you have to, but would be simpler if you had it working. 1 Link to comment Share on other sites More sharing options...
Recommended Posts