GoogieHost Posted May 8, 2021 Share Posted May 8, 2021 Hi, I want to send my customer's email notification that their order has been cancelled with reasons, I have checked but there is no option to set template for this. Is there any way to set this Email alert for my customers? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 9, 2021 Share Posted May 9, 2021 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. 0 Quote Link to comment Share on other sites More sharing options...
GoogieHost Posted May 9, 2021 Author Share Posted May 9, 2021 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 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 9, 2021 Share Posted May 9, 2021 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. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.