Jump to content

Email on Order Cancellation


GoogieHost

Recommended Posts

14 hours ago, GoogieHost said:

Is there any way to set this Email alert for my customers?

you could use a CancelOrder hook, in which you can use the SendEmail API to either send a pre-existing template (default or custom), or just create a custom message within the API code itself.

you could use the order notes option to enter/save the reasons before cancelling the order - the hook will know the Order ID value, so then it's just a case of pulling the cacellation notes from the relevant record in tblorders, getting the client ID value in the same way and then using that info in the API call.

Link to comment
Share on other sites

38 minutes ago, brian! said:

you could use a CancelOrder hook, in which you can use the SendEmail API to either send a pre-existing template (default or custom), or just create a custom message within the API code itself.

you could use the order notes option to enter/save the reasons before cancelling the order - the hook will know the Order ID value, so then it's just a case of pulling the cacellation notes from the relevant record in tblorders, getting the client ID value in the same way and then using that info in the API call.

looks complicated for me and think will have to hire developer 

Link to comment
Share on other sites

1 hour ago, GoogieHost said:

looks complicated for me and think will have to hire developer 

fundamentally, it's just the hook below - to save time/explanation, i'm not creating a custom email template, i'm outputting the content directly into the email via the API.

<?php

use WHMCS\Database\Capsule;
use WHMCS\User\Client;

add_hook('CancelOrder', 1, function($vars) {
	
	$orderid = $vars['orderid'];
	$orderdetails = Capsule::table('tblorders')->where('id',$orderid)->first();
	$userid = $orderdetails->userid;
	$notes = $orderdetails->notes;
	$client = Client::find($userid);
	$clientname = $client->fullName;	
	$postData = array(
		'id' => $userid,
		'customtype' => 'general',
		'customsubject' => 'Order Cancellation',
		'custommessage' => '<p>Dear {$clientname},</p><p>Your order has been cancelled for the following reason(s):</p><p>{$cancelreason}</p>',
		'customvars' => base64_encode(serialize(array("clientname" => $clientname, "cancelreason" => $notes))),
	);
	$results = localAPI('SendEmail', $postData);
	print_r($results);
});

so upon cancelling an order, and assuming you had first entered the reasons into the order notes, the client should receive an email with the content along the lines of...

Quote

Dear John Smith,

Your order has been cancelled for the following reason(s):

*content of order notes field*

depending on what the content is going to be, it might be easier to create an email template for this and use it in the API instead.... otherwise, just create additional custom variables as and when needed.

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