Timothé Posted May 11, 2023 Share Posted May 11, 2023 Hey guys, I there a way to disable the invoice-created email, but just the first one (That is sent when an order Is created) Thanks, Tim 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted May 13, 2023 Share Posted May 13, 2023 (edited) 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 May 13, 2023 by Kian 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.