Jump to content

Prevent sending invoice payment reminder


Basheer

Recommended Posts

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;
});

 

Link to comment
Share on other sites

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

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 by twhiting9275
Link to comment
Share on other sites

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

Guest
This topic is now closed to further replies.
  • 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