Jump to content
Sign in to follow this  
pKris

Disable email template (eg. Invoice Generation Notification) for specific clients

Recommended Posts

We've run into a few clients who only want payment receipts, but do not want invoice generation emails (if fact they're pretty insistent on this) - I could, of course disable the invoice generation email entirely but they're the minority in our client group. I'm thinking I could accomplish this with a hook, but wanted to pass it to the community to see if anyone has also done this in their environment and if anyone had any tips from their experience..

Share this post


Link to post
Share on other sites

Create a client custom field "Send Invoice Generation Emails".  In preemailsend hook, see if sending invoice generation email and then check if client sending to has the custom field set and take action as needed. 

Share this post


Link to post
Share on other sites

Thank you for the input that's exactly what I'd created while I waited for a response, actually:

 

<?php

add_hook('EmailPreSend', 1, function($vars) {
    $merge_fields = [];
    if ($vars['messagename'] == 'Invoice Created' && $vars['email'] == 'email@domain.org') {
        //Stop the email from sending a specific message and related id.
        $merge_fields['abortsend'] = true;
    }
    return $merge_fields;
});

 

However it didn't work so I'm just debugging that now.

Edited by pKris

Share this post


Link to post
Share on other sites
On 10/6/2021 at 10:21 PM, pKris said:

Thank you for the input that's exactly what I'd created while I waited for a response, actually:

 

<?php

add_hook('EmailPreSend', 1, function($vars) {
    $merge_fields = [];
    if ($vars['messagename'] == 'Invoice Created' && $vars['email'] == 'email@domain.org') {
        //Stop the email from sending a specific message and related id.
        $merge_fields['abortsend'] = true;
    }
    return $merge_fields;
});

 

However it didn't work so I'm just debugging that now.

Hi,

Your second conditional is $vars['email'] == 'email@domain.org', the issue is that $vars['email'] does not exist. Take a look at https://developers.whmcs.com/hooks-reference/everything-else/#emailpresend you will see that the hook has 3 variables in $vars = messagename, relid and mergefields.

Say I want to solve this for 1 specific user, say user "234"

if ($vars['messagename'] == 'Invoice Created') {
	$userID = Capsule::table('tblinvoiceitems')
    ->where('tblinvoiceitems.invoiceid', $invoiceID)
    ->value('userid');
	
	if ($userID == 234) {
		$merge_fields['abortsend'] = true;
	}
	return $merge_fields;
}

If you have multiple users who does not want invoice emails, it might be best to create a customField. Then you can check for the customFIeld value instead of hardcoded email domains or userid.

 

Share this post


Link to post
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.

Sign in to follow this  

  • 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