Jump to content

Remove invoice created email for first invoice


Timothé

Recommended Posts

Yes, via action hook. Use EmailPreSend to detect when WHMCS is attempting to send the "Invoice Created" (messagename) email. If that's the case relid equals to invoice Id. Use it for retreiving the Id of the customer as follows.

 SELECT userid FROM tblinvoices WHERE id = {YOUR_RELID_AKA_INVOICE_ID} LIMIT 1

Now that you know userid simply count how many invoices the user in question has (I'm not counting Draft invoices):

SELECT count(id) AS invoice_count FROM tblinvoices WHERE userid = {USER_ID} AND status NOT IN ("Draft")

If invoice_count is = 1 return abortsend to prevent WHMCS from sending the email. Even better you could simply try to select the first two invoices as follows:

SELECT id FROM tblinvoices WHERE userid = {USER_ID} AND status NOT IN ("Draft") LIMIT 2

The count() in PHP if returned rows are 1 (abortsend) or 2 (don't do anything) This is approach is more efficient since you stop the SELECT as soon as it finds 2 invoices instead of counting them all.

-----

In case you want to suppress email sending for every new hosting/service purchase the logic is the same. In EmailPreSend hook point run a query to retreive the product Id:

SELECT
	tblinvoiceitems.relid AS product_id
FROM
	tblinvoices
LEFT JOIN
	tblinvoiceitems ON tblinvoices.id = tblinvoiceitems.invoiceid
WHERE
	tblinvoices.id = {YOUR_RELID_AKA_INVOICE_ID} AND
	tblinvoices.status NOT IN ("Draft") AND
	tblinvoiceitems.type = "Hosting"
LIMIT 1

Now count in how many times the product Id in question appears on invoices:

SELECT
	COUNT(tblinvoiceitems.id) AS invoice_count
FROM
	tblinvoices
LEFT JOIN
	tblinvoiceitems ON tblinvoices.id = tblinvoiceitems.invoiceid
WHERE
	tblinvoices.relid = {YOUR_PRODUCT_ID} AND
	tblinvoices.status NOT IN ("Draft") AND
	tblinvoiceitems.type = "Hosting"

Or even better the LIMIT 2 approach:

SELECT
	tblinvoiceitems.id
FROM
	tblinvoices
LEFT JOIN
	tblinvoiceitems ON tblinvoices.id = tblinvoiceitems.invoiceid
WHERE
	tblinvoices.relid = {YOUR_PRODUCT_ID} AND
	tblinvoices.status NOT IN ("Draft") AND
	tblinvoiceitems.type = "Hosting"
LIMIT 2

 

Edited by Kian
Link to comment
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.

  • 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