ScottN Posted January 18, 2016 Share Posted January 18, 2016 I'm trying to customize the "Upcoming Domain Renewal Notice" Email Template. Specifically, I'd like to let the customer know if they have "Auto Renew" enabled, if the domain expires more than 30 days from now. For example, I might want to do something like: {if $days_until_expiry > 30}{if $domain_do_not_renew eq "0"}You currently have Auto-Renew enabled, so an invoice for this domain renewal will be generated 30 days before expiration.{/if}{/if} I can't seem to find any documentation on what the options are with the "if" statements in the email templates, other than I see I can use "eq" to mean =. Any push in the right direction, as far as syntax or logic goes, would be greatly appreciated! - Scott Link to comment Share on other sites More sharing options...
brian! Posted January 18, 2016 Share Posted January 18, 2016 Scott, here's three links for you... first two are basics about syntax, the third is the Smarty documentation for {if} - you've probably already read the first two, so go straight to the third! http://docs.whmcs.com/Email_Templates http://docs.whmcs.com/Template_Syntax http://www.smarty.net/docs/en/language.function.if.tpl assuming both your {if} statements work, you could combine them into one using 'and'... {if $days_until_expiry > 30 AND $domain_do_not_renew eq "0"}You currently have Auto-Renew enabled, so an invoice for this domain renewal will be generated 30 days before expiration.{/if} Link to comment Share on other sites More sharing options...
ScottN Posted January 18, 2016 Author Share Posted January 18, 2016 Hi Brian! The first two links I've read about 10 times before and were not helping me at all, but your third link is GOLD! I'm new to both WHMCS and Smarty, and while I knew that we were using Smarty for page templates, I did not realize I was looking at smarty code in those email templates. THANK YOU! I'll give your combined code a try and report back. My one concern is that it won't be evaluating the numbers as numbers... so, it might think that 30 is actually less than 7, if it just sees these "numbers" as text strings. I guess I'll know soon enough. - Scott Link to comment Share on other sites More sharing options...
ScottN Posted January 22, 2016 Author Share Posted January 22, 2016 Well, bad news to report... I didn't realize it, but since adding that code to my template, Upcoming Domain Renewal Notices are NOT BEING SENT AT ALL. I didn't have any indication that there was a problem, but apparently if there is bad smarty code in the template, it just won't send. Hmmm... - Scott Link to comment Share on other sites More sharing options...
brian! Posted January 22, 2016 Share Posted January 22, 2016 (edited) Scott, anything in the activity log ? if you have a domain you can test the template on, you could manually send a UDR email via the Client's profile, selecting the domain and choosing the email template from the bottom of the page. it should send, but if it contains Smarty errors, they should appear in the activity log... or at least a hint at where to look. Edited January 22, 2016 by brian! Link to comment Share on other sites More sharing options...
ScottN Posted January 22, 2016 Author Share Posted January 22, 2016 Brian!, thanks for being there for us "newbs" -- I really appreciate it! Sure enough, I see this in the activity log: Smarty Error: Syntax error in template "mailTemplate:plaintext" on line 13 "<p>{$signature}<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><span style="color: #c0c0c0;">Auto-Renew Status: {if $domain_do_not_renew eq "0"}Enabled<span>{else}Disabled<span>{/if}<br /><span><br /></span><span>{if </span><span>$days_until_expiry </span><span>> </span><span>30 </span><span>AND </span><span>$domain_do_not_renew eq </span><span>"0"</span><span>}</span><span>You currently have Auto</span><span>-</span><span>Renew enabled</span><span>, </span><span>so an invoice </span><span>for </span><span>this domain renewal will be generated 30 days before expiration</span><span>.{/if} </span><br /></span></span></span></p>" - Unexpected " Smarty Error: Syntax error in template "mailTemplate:message" on line 14 "<p>{$signature}<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><span style="color: #c0c0c0;">Auto-Renew Status: {if $domain_do_not_renew eq "0"}Enabled<span>{else}Disabled<span>{/if}<br /><span><br /></span><span>{if </span><span>$days_until_expiry </span><span>> </span><span>30 </span><span>AND </span><span>$domain_do_not_renew eq </span><span>"0"</span><span>}</span><span>You currently have Auto</span><span>-</span><span>Renew enabled</span><span>, </span><span>so an invoice </span><span>for </span><span>this domain renewal will be generated 30 days before expiration</span><span>.{/if} </span><br /></span></span></span></p>" - Unexpected " Here is what I see in the Template Editor: Auto-Renew Status: {if $domain_do_not_renew eq "0"}Enabled{else}Disabled{/if} {if $days_until_expiry > 30 AND $domain_do_not_renew eq "0"}You currently have Auto-Renew enabled, so an invoice for this domain renewal will be generated 30 days before expiration.{/if} I don't see any extra double quotes, as it says. I wonder if I should be using single quotes around the numbers? (i.e. eq '0' vs eq "0") ? - Scott Link to comment Share on other sites More sharing options...
brian! Posted January 22, 2016 Share Posted January 22, 2016 I don't see any extra double quotes, as it says. I wonder if I should be using single quotes around the numbers? (i.e. eq '0' vs eq "0") ? single quotes would be better, but if the value is an integer, you shouldn't need any... try '0' and if that doesn't work, try 0 Link to comment Share on other sites More sharing options...
ScottN Posted January 22, 2016 Author Share Posted January 22, 2016 Through a lot of trial and error, I have it working! A few things that might help others that find this thread later... 1) No quotes are necessary. You can just do it like {if $domain_do_not_renew eq 0} 2) I am not sure yet what the difference is between $days_until_expiry and $domain_days_until_expiry, but I found that I needed the second one, to produce the number of days before the domain expires. 3) I think the > symbol was giving me some grief. Per the Smarty docs you linked to, you can also use gt as a substitute for > (they both mean Greater Than). So, I changed > to gt. 4) There must have been some stray bad code that I just wasn't seeing... even after getting everything right, I was still getting odd errors about an unexpected double-quote (which did not exist, even when I disabled the Rich Text Editor and I removed them all!) I wound up deleting that whole section, and then pasting in the same code, in plain text from Notepad, and it stopped giving errors! Now the reminders will actually send without errors. I need to do more testing to be sure it's all working perfectly, but I'm optimistic. Here is the final code I wound up with... this gives the customer a different message depending on whether Auto Renew is enabled or disabled... tells them an invoice will be issued automatically if auto-renew is enabled... and tells them they have to manually renew the domain if auto-renew is disabled. Pretty good idea, if you ask me. Auto-Renew Status: {if $domain_do_not_renew eq 0}Enabled{else}Disabled{/if} {if $domain_days_until_expiry gt 30 AND $domain_do_not_renew eq 0}NOTE: Since you currently have Auto-Renew enabled, an invoice for this domain renewal will be generated and emailed to you 30 days before the domain expiration date. If you do not wish to renew this domain, please login and disable Auto-Renew.{/if}{if $domain_do_not_renew eq 1}NOTE: Since you currently have Auto-Renew disabled, you will have to log into our website and manually renew this domain. See the domain management section of our client area at {$whmcs_link}{/if} - Scott Link to comment Share on other sites More sharing options...
brian! Posted January 22, 2016 Share Posted January 22, 2016 2) I am not sure yet what the difference is between $days_until_expiry and $domain_days_until_expiry, but I found that I needed the second one, to produce the number of days before the domain expires. http://forum.whmcs.com/showthread.php?83163-Difference-between-days_until_expiry-and-domain_days_until_expiry&p=353842#post353842 I think the first is used on the emails sent on the 11th of each month; the second is used when its triggered by the domain reminder settings in the automation settings. Link to comment Share on other sites More sharing options...
blakeh Posted January 30, 2016 Share Posted January 30, 2016 Thank you for this code! Link to comment Share on other sites More sharing options...
ScottN Posted January 30, 2016 Author Share Posted January 30, 2016 Thank you for this code! Glad it was of use! I had to tweak this further, for domain renewal notifications that are less than 30 days (since the invoice is already generated but not yet due). If you are interested in seeing my final code, let me know. - Scott Link to comment Share on other sites More sharing options...
heapmaster Posted February 2, 2018 Share Posted February 2, 2018 I would like to see the finial email template code please, our clients complain about the email not showing the auto renew status as well. Link to comment Share on other sites More sharing options...
Recommended Posts