Jump to content

send email on new order.


Recommended Posts

I need to make a hook so when a new order is placed, and the payment method 'PayPal' is selected, email template (Insert number here) is automatically sent, and if payment method 'Credit Card' is selected, email template (Insert number here) is automatically sent.

 

I am trying to combat fraud, and want all new orders and the clients to sign an agreement and payment release form and up to now I have been manually reviewing orders, and with the influx in recent orders, automation would be nice.

 

any help ?

Link to comment
Share on other sites

I have created a new email template to include both payment methods and instructions on how to submit the documents. I just need to know how I can make the template be sent out after a order is placed when the invoice is being created.

oh I assumed you were going to be editing one of the existing email templates that are automatically sent (Order Confirmation, Invoice or optionally a Product Welcome). :?:

 

of the three, i'd have been more tempted to add this text to an existing invoice email template - for two reasons...

 

1. in the invoice templates, you'd automatically have access to the {$invoice_payment_method} Smarty variable - and that would give you a value to base a simple {if} statement on to determine the appropriate text to add... a similar variable exists in the Product Welcome templates too.

 

{if $invoice_payment_method eq "Paypal"}some text{else}some other text{/if}

 

2. by default, WHMCS uses two different email templates for invoice creation - one for Credit Cards and one for other payment gateways - so you should automatically have a built-in method of differentiating your credit card and paypal customers.

 

http://docs.whmcs.com/Payment_Gateways

 

The type of payment gateway selected influences which invoice notification email template it sent; Third Party Gateways will send the "Invoice Created" email template, whilst Merchant and Tokanisation Gateways will send the "Credit Card Invoice Created" email template. This allows you to customise the payment instructions to clients for the different payment processes.

optionally, I suppose if your release form is a PDF document, you could also attach the appropriate version to the specific invoice email template. :idea:

Link to comment
Share on other sites

Will this work ?

 

 

{if $invoice_payment_method eq "PayPal"}
PayPal Info Here
{elseif $invoice_payment_method eq "Stripe"}
Credit Card Info Here
{elseif $invoice_payment_method eq "Offline Credit Card"}
Offline Credit Card Process Here
{elseif $invoice_payment_method eq "Mail In Payment"}
e-Transfer Process Here
{else}
Main Order Confirmation Here
{/if} 

Edited by AffordableDomainsCanada
Link to comment
Share on other sites

Will this work ?

it should now that you've changed the code to use elseif - but create a test account within your WHMCS, make a dummy order or invoice, change the payment method in the admin area, send the email again and ensure the text is showing correctly for each.

Link to comment
Share on other sites

Okay I think I got it working how it should be but then I got thinking, this is going to send everytime the gateway is triggered. is there a way to make it so its displayed ONLY for new orders ? for existing clients when the invoice created template is sent, the paragraph in the {else} will be displayed .. hope that makes sense

Link to comment
Share on other sites

I think i got it working, it was the email template I was using.

it sounded like you were still trying to do it in the order confirmation email, and not the invoice templates... with WHMCS, always remember that the general emails don't necessarily have access to invoice variables... and the invoice templates don't have full access to the order details.

 

Okay I think I got it working how it should be but then I got thinking, this is going to send everytime the gateway is triggered. is there a way to make it so its displayed ONLY for new orders ? for existing clients when the invoice created template is sent, the paragraph in the {else} will be displayed .. hope that makes sense

it makes sense... but the simplest test for new orders is whether an orderID exists... if so, it's an order; if not, it's a renewal invoice - there are potential exceptions to that rule, but in general it's true... but the invoice email templates don't have access to the order number, so that's irrelevant... unless you wrote a hook to give it that info, but we're on the road of trying to avoid hooks with this. :idea:

 

about the only practical way I can think to do this, using existing invoice email template variables, would be to test if the invoice and signup dates are the same - if so, they're a new customer and it's their 1st invoice*; if they don't match, then it's a new order at a later date, or a renewal, from an existing client.

 

{if $invoice_date_created == $client_signup_date}
   {if $invoice_payment_method eq "PayPal"}
       PayPal Info Here
   {elseif $invoice_payment_method eq "Stripe"}
       Credit Card Info Here
   {elseif $invoice_payment_method eq "Offline Credit Card"}
       Offline Credit Card Process Here
   {elseif $invoice_payment_method eq "Mail In Payment"}
       e-Transfer Process Here
   {/if}
{else}
   Main Order Confirmation Here
{/if}

note - i've moved your else out of the first {if} block into the second.

 

* I can only see two potential flaws with this - one is reasonably possible, the other is extraordinarily unlikely.

 

1. if the new customer made multiple orders (generating multiple invoices) on their signup date, then they would all show the additional information... it's possible that a customer could do this, but I wouldn't have thought it likely... and i'm not talking about ordering multiple items in one go, but them making one order, then another, then another on that same first day etc...

2. if the order. from a new customer, was made at 23:59:59 and for some reason, e.g. server load, the signup/invoices dates were different - but I would have thought that would be freakishly unlikely to occur. :evil:

 

other that that, it should work. :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.

  • 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