MAqib1087 Posted December 26, 2024 Share Posted December 26, 2024 I want to make hook that abort all email unless client have a paid invoice in his account. 0 Quote Link to comment Share on other sites More sharing options...
Azhar Patel Posted December 28, 2024 Share Posted December 28, 2024 Hello @MAqib1087 You can try with below code it should work add_hook('EmailPreSend', 1, function($vars) { // Get the client ID from the email variables $clientId = $vars['clientid']; // Check if the client has any paid invoices $paidInvoices = \App\Models\Invoice::where('client_id', $clientId) ->where('status', 'Paid') ->count(); // If the client has no paid invoices, abort the email if ($paidInvoices == 0) { return 'abort'; } }); 0 Quote Link to comment Share on other sites More sharing options...
MAqib1087 Posted December 30, 2024 Author Share Posted December 30, 2024 5 hours ago, markwilly said: You can set up a system that checks whether a client has a paid invoice before sending any emails. If the client doesn't have a paid invoice, the email won't be sent. This ensures that only clients with active, paid invoices will receive communication I want someone to do it for me to make sure it works 100%. On 12/28/2024 at 12:38 PM, WHMCS Solution said: Hello @MAqib1087 You can try with below code it should work add_hook('EmailPreSend', 1, function($vars) { // Get the client ID from the email variables $clientId = $vars['clientid']; // Check if the client has any paid invoices $paidInvoices = \App\Models\Invoice::where('client_id', $clientId) ->where('status', 'Paid') ->count(); // If the client has no paid invoices, abort the email if ($paidInvoices == 0) { return 'abort'; } }); I have tried many codes but does not work. Anyone? 0 Quote Link to comment Share on other sites More sharing options...
MAqib1087 Posted January 1 Author Share Posted January 1 On 12/28/2024 at 12:38 PM, WHMCS Solution said: Hello @MAqib1087 You can try with below code it should work add_hook('EmailPreSend', 1, function($vars) { // Get the client ID from the email variables $clientId = $vars['clientid']; // Check if the client has any paid invoices $paidInvoices = \App\Models\Invoice::where('client_id', $clientId) ->where('status', 'Paid') ->count(); // If the client has no paid invoices, abort the email if ($paidInvoices == 0) { return 'abort'; } }); we got this error after your code Error: Class 'App\Models\Invoice' not found in 0 Quote Link to comment Share on other sites More sharing options...
Azhar Patel Posted January 6 Share Posted January 6 @MAqib1087 try below code use WHMCS\Database\Capsule; add_hook('EmailPreSend', 1, function($vars) { // Get the client ID from the email variables $clientId = $vars['clientid']; // Check if the client has any paid invoices $paidInvoices = Capsule::table('tblinvoices') ->where('client_id', $clientId) ->where('status', 'Paid') ->count(); // If the client has no paid invoices, abort the email if ($paidInvoices == 0) { return 'abort'; } }); 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.