Jump to content

Problem with {if} in notification emails. Maybe variable not used?


-M-

Recommended Posts

I am currently redoing the notification email, which the customer receives when they place an order, however I am experiencing a minor issue with this email. The email template I am currently modifying is: "Order Confirmation"

 

I am trying to create several {if} rules depending on the product / service a customer orders, however for some reason it's not working. I am starting to think the variable I am using is not being used in the template?

 

The one I am using, which I found in a different email template, is: $service_product_name

 

As mentioned, the {if} statement didn't work. At first I thought I did it wrong, then I just pasted {$service_product_name} into the email to see the output, however nothing is shown.

 

Does this mean that this variable is not in use for this email? Or am I calling this variable wrongly and is a different approach needed for this?

 

Sorry if this is a stupid question, but it's my first attempt at modifying the email templates.

 

Sidenote; I doubt I can use {debug} right? :P

 

Thank you in advance.

 

Regards

Link to comment
Share on other sites

The one I am using, which I found in a different email template, is: $service_product_name

 

As mentioned, the {if} statement didn't work. At first I thought I did it wrong, then I just pasted {$service_product_name} into the email to see the output, however nothing is shown.

well done for pasting the variable in the template to see the output, that was the correct thing to try. :idea:

 

Does this mean that this variable is not in use for this email? Or am I calling this variable wrongly and is a different approach needed for this?

if there was no output, then that would probably mean that the variable is not available to that template.

 

http://docs.whmcs.com/Email_Templates#Merge_Fields

 

The merge fields available in your message depend on what type of email you are sending. For example if it's an email related to a client you can include client fields only, but if it's a product related email you could include product details as well as client fields.

 

The exact list of fields you have available in any email message you are composing are listed directly below the message box with the field description and merge field code. Clicking on the description will insert the merge field at the point of your cursor in the message.

{$service_product_name} will be a product merge field - so probably only available in the Product/Service email templates.

 

if you know how to find the variable you want, you can use a hook to make it available to the email template - Hooks:EmailPreSend - but you'll probably need to query the database to get the value you want to pass to the template.

 

a basic example of passing new variables to the template is shown in the thread below...

 

http://forum.whmcs.com/showthread.php?98066-Hooks-and-or-email-merge-fields-for-custom-urls

 

Sorry if this is a stupid question, but it's my first attempt at modifying the email templates.

Sidenote; I doubt I can use {debug} right? :P

it wasn't a stupid question as it's not obvious that you can only use some merge fields in specific template types... would be useful if they were available to all templates, I don't think there's a technical reason why they aren't.

 

and you are correct - {debug} is not an option in the email templates.

Link to comment
Share on other sites

Not again those damn hooks... :|

I haven't created a succesful hook, other then replacing panels and links in the client area.

 

I was expecting the email templates to work easier, but apparently I was mistaken here.

 

I took a short look at those links, but understanding it, even if it was in Dutch, it's hard, let alone in English. What I don't understand is, is that when you use {$order_details} all information is in there, even the stuff I want to display, however I don't want to display it all, only parts of it.

 

So, even though {$order_details} includes it all, it's not possible to output a few things from that, without creating a hook and query the database? Uhmz...

 

Will look into this later, but it's kinda demotivating. :|

 

Anyways, thank you for replying. Will report back if I have tried something.

 

//edit

 

I don't understand why I should use custom fields? Isn't it a product or service a default item? The only thing I am trying to do is to display what a customer ordered, but without prices and the other stuff (so less output than with {$order_details}).

 

Also where do I add 'messagename' and how do I figure out the email template name? Or is 'Order Confirmation' the name of the template? :oops:

 

Man this is way harder than a few {if} statements lol. Maybe I should just create a simple email, stating thanks for the order. But that would be a decline in comprism to our current ordering system / emails which are send when an order is placed.

 

I don't understand why this have to be so difficult. Probably easy for scripters and developers, but for plain simple people like me, this hook stuff is like magic. :(

Edited by MvdL1979
Link to comment
Share on other sites

Not again those damn hooks... :|

I haven't created a successful hook, other then replacing panels and links in the client area.

well it's a start! :)

 

I was expecting the email templates to work easier, but apparently I was mistaken here.

without {debug}, it's takes longer to test the email templates Smarty code, as you need to test by sending yourself an email.

 

I took a short look at those links, but understanding it, even if it was in Dutch, it's hard, let alone in English. What I don't understand is, is that when you use {$order_details} all information is in there, even the stuff I want to display, however I don't want to display it all, only parts of it.

 

So, even though {$order_details} includes it all, it's not possible to output a few things from that, without creating a hook and query the database? Uhmz...

I think $order_details was created as just one variable to make it simpler in the template - which in one way it does... but I can remember first using WHMCS a few years ago and being frustrated that it was one long variable and difficult to split... if they'd passed all parts of it as separate variables, it would have made it easier to modify the output. :roll:

 

but don't forget that $order_details is just a Smarty variable - so you can replace parts of it as i've previously shown - even if you can't use an in-built Smarty command, you can use most PHP commands too... it probably won't be easy, but depending on what you want to take from $order_details, it might be simpler for you than using a hook.

 

the difficulty is that there will be parts of the variable that you don't know., e.g any ordered domain name will be different for each order, so you can't just use 'replace' as you don't know what the domain is... technically, you'd need to use regex_replace and regular expressions - but that's another level up from using standard replace. :)

 

I don't understand why I should use custom fields? Isn't it a product or service a default item? The only thing I am trying to do is to display what a customer ordered, but without prices and the other stuff (so less output than with {$order_details}).

because you're trying to display a variable (merge field) that doesn't exist in your chosen template type - so your only options are to either modify another available variable via Smarty, or use a hook to add the merge field to your chosen template.

 

Man this is way harder than a few {if} statements lol. Maybe I should just create a simple email, stating thanks for the order. But that would be a decline in comparison to our current ordering system / emails which are send when an order is placed.

as an alternative solution, have you thought about disabling the "Order Notification" email template, and sending a "Welcome Email" (a product email template) instead?

 

each product can be assigned to use a different Product email template, and the email is sent when the product is activated... the order notification would be sent at the time of order, but if activation is automatic after payment, the welcome email will be sent at virtually the same time.

 

from your point of view, the biggest difference is that in a Product email template, you'll have access to the variables you want - so if you just want to show the product name in that template, use {$service_product_name} :idea:

 

it might be worth considering as it will be simpler to do that than using Smarty or hooks or modify the Order Notification template.

Link to comment
Share on other sites

Sorry about to leave, but did want to respond to your last part in regards to sending the customers a "Welcome Email".

 

That's not an option. We don't use WHMCS billing / payment system and those emails aren't used. That's why we are spending a small fortune already on modifications. And I don't think my boss will agree on more modifications. WHMCS is already becoming expensive for us as it is.

 

Wish I would have checked the mail templates earlier, because this will be a dealbreaker for my boss.

 

Oh well; guess I will look into the other stuff you mentioned. For now I am completely done with WHMCS. I sincerely thought after doing all cart and order templates, that it would be a walk in the park for setting up emails. Badly mistaken there.

 

Anyways, thank you for the reply nevertheless.

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