Basheer Posted February 27, 2018 Share Posted February 27, 2018 Hi, Is there any option to prevent sending invoice payment reminder for a particular customer, if i am enabled the automation ? Link to comment Share on other sites More sharing options...
Basheer Posted February 27, 2018 Author Share Posted February 27, 2018 I created a hook for that, It's worked. add_hook('EmailPreSend', 1, function($vars) { $merge_fields = []; if ($vars['messagename'] =='Invoice Payment Reminder') { //get customer id fom invoice id $invoice_id = $vars['relid']; $invoice_sql = Capsule::table('tblinvoices') ->where('id','=',$invoice_id) ->first(); $userid = $invoice_sql->userid; $blocked_ids = array(11,12); if(in_array($userid,$blocked_ids)) { $merge_fields['abortsend'] = true; } } return $merge_fields; }); 1 Link to comment Share on other sites More sharing options...
sentq Posted February 27, 2018 Share Posted February 27, 2018 this should do the trick, create new {File-Name}.php file inside /includes/hooks/ directory and place the following lines inside it: <?php /** * Prevent "Invoice Payment Reminder" email from being sent to specific clients * * @author SENTQ */ use WHMCS\Database\Capsule; add_hook("EmailPreSend", 1, function($vars){ $clientIds = array(1, 12, 25); if ($vars['messagename'] === "Invoice Payment Reminder"){ $getClientId = Capsule::table("tblinvoices")->where("id", "=", $vars['relid'])->first(); if (in_array($getClientId->userid, $clientIds)){ return array("abortsend" => true); } } }); Link to comment Share on other sites More sharing options...
twhiting9275 Posted February 27, 2018 Share Posted February 27, 2018 (edited) As always, more than one way to skin a cat. This would be an excellent utilization of client groups . No arrays , or future editing necessary, just move any clients into said usergroup, change the grouptoabort (at the top) and bam, you're done <?php add_hook('EmailPreSend', 1, function($vars) { $merge_fields = []; $grouptoabort = 1234567; if ($vars['messagename'] =='Invoice Payment Reminder') { //get customer id fom invoice id $invoice_id = $vars['relid']; $invoice_sql = Capsule::table('tblinvoices') ->where('id','=',$invoice_id) ->first(); $userid = $invoice_sql->userid; $usergroup = Capsule::table('tblclients')->WHERE('id', $userid)->fetch('groupid'); if ($usergroup = $grouptoabort ) { $merge_fields['abortsend'] = true; } } return $merge_fields; }); Edited February 27, 2018 by twhiting9275 Link to comment Share on other sites More sharing options...
brian! Posted February 27, 2018 Share Posted February 27, 2018 11 minutes ago, twhiting9275 said: just move any clients into said usergroup shouldn't 'fetch' be 'value' for the recent WHMCS versions... or even 'first', because there should only be one valid value anyway? $usergroup = Capsule::table('tblclients')->WHERE('id', $userid)->value('groupid'); Link to comment Share on other sites More sharing options...
twhiting9275 Posted February 27, 2018 Share Posted February 27, 2018 (edited) Hey, I'm over here still using pluck and array checks, so, if it should be, my bad Edited February 27, 2018 by twhiting9275 Link to comment Share on other sites More sharing options...
Recommended Posts