Jump to content

Arithmetic in email template


didier1

Recommended Posts

Hello, I'm trying to find documentation to see if this is possible to use Arithmetic calculation in WHMCS email template.

Example within an email template : SomeVar * 12/100.

the email templates use Smarty, so the answer is yes. :idea:

 

assuming the variable you're trying to manipulate is a number and not a string, then you can do something like this to find 12%...

 

{$somevar * (12/100)}

if you need to set it to 2 decimal places...

 

{($somevar * (12/100))|string_format:"%.2f"}

if you're doing this in v7, you'll need to add string_format to your Smarty Security Policy - otherwise the emails won't send.

 

if you're wanting to do this to a variable that is a string, e.g an amount such as $123.45 USD, then you'd first need to remove the currency prefix/suffix, and then you can do your calculation as above..

 

{(($somevar|replace:'$':''|replace:'USD':'') * (12/100))|string_format:"%.2f"}

if you're using multiple currencies in your setup, then the required code gets more complicated - but not impossible to do. :idea:

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.

×
×
  • 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