SeanP Posted May 10, 2021 Share Posted May 10, 2021 I need to hide certain product custom fields from all the email templates where they would be displayed. Basically any of the email templates where {$invoice_html_contents} is used. Is there an easy was to do this with a hook for all templates, or would I have to do it for each template? 0 Quote Link to comment Share on other sites More sharing options...
SeanP Posted May 10, 2021 Author Share Posted May 10, 2021 (edited) It looks like I need to hide certain product custom fields in the following email templates: Invoice Payment Confirmation Credit Card Payment Confirmation Order Confirmation Invoice Created Invoice Modified The custom fields are being displayed from the following 2 tags: {$invoice_html_contents} {$order_details} These custom fields have to be visible (cannot be set to Admin Only) for functionality in custom modules. We have them hidden everywhere else, we just noticed they are displaying in some email templates. Edited May 10, 2021 by SeanP 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 10, 2021 Share Posted May 10, 2021 3 hours ago, SeanP said: Is there an easy was to do this with a hook for all templates, or would I have to do it for each template? I would expect that it should only need to be one EmailPreSend hook, with 2 conditions within it - if order confirmation, modify the $order_details variable; if one of the listed invoice templates, modify $invoice_html_contents. I think in both cases, those variables are HTML strings - so if you know the values/content of those customfield lines, then you might get away with just using a string replace on them; if not, you might need to explode them into an array and remove these fields that way. 0 Quote Link to comment Share on other sites More sharing options...
SeanP Posted May 10, 2021 Author Share Posted May 10, 2021 6 hours ago, brian! said: I would expect that it should only need to be one EmailPreSend hook, with 2 conditions within it - if order confirmation, modify the $order_details variable; if one of the listed invoice templates, modify $invoice_html_contents. I think in both cases, those variables are HTML strings - so if you know the values/content of those customfield lines, then you might get away with just using a string replace on them; if not, you might need to explode them into an array and remove these fields that way. Thanks. I guess to start I need to figure out what format those two variables are in. 0 Quote Link to comment Share on other sites More sharing options...
SeanP Posted May 10, 2021 Author Share Posted May 10, 2021 9 hours ago, brian! said: I would expect that it should only need to be one EmailPreSend hook, with 2 conditions within it - if order confirmation, modify the $order_details variable; if one of the listed invoice templates, modify $invoice_html_contents. I think in both cases, those variables are HTML strings - so if you know the values/content of those customfield lines, then you might get away with just using a string replace on them; if not, you might need to explode them into an array and remove these fields that way. Sorry for my ignorance, but I haven't done a whole lot with the emailpresend hook. How to you pull in the $invoice_html_contents and/or $order_details variables into the hook? 0 Quote Link to comment Share on other sites More sharing options...
SeanP Posted May 10, 2021 Author Share Posted May 10, 2021 I figured it out: if ($vars['messagename'] == "Order Confirmation"){ $order_details = $vars['mergefields']['order_details']; } 0 Quote Link to comment Share on other sites More sharing options...
SeanP Posted May 11, 2021 Author Share Posted May 11, 2021 So here is my final result: function email_presend_filter($vars) { if (isset($vars['mergefields']['order_details'])){ $ordercontents = $vars['mergefields']['order_details']; $ordercontents = preg_replace('/^ITEMTOREMOVE.*?<br>$/m', '', $ordercontents); $merge_fields['order_details'] = $ordercontents; return $merge_fields; } if (isset($vars['mergefields']['invoice_html_contents'])){ $invoicecontents = $vars['mergefields']['invoice_html_contents']; $invoicecontents = preg_replace('/^ITEMTOREMOVE.*?<br>$/m', '', $invoicecontents); $merge_fields['invoice_html_contents'] = $invoicecontents; return $merge_fields; } } add_hook("EmailPreSend", 1, "email_presend_filter"); If you replace "ITEMTOREMOVE" with the custom field name you want removed from order confirmations and invoice emails, it will remove the line where that field resides. 0 Quote Link to comment Share on other sites More sharing options...
SeanP Posted May 18, 2021 Author Share Posted May 18, 2021 On 5/10/2021 at 2:56 AM, brian! said: I would expect that it should only need to be one EmailPreSend hook, with 2 conditions within it - if order confirmation, modify the $order_details variable; if one of the listed invoice templates, modify $invoice_html_contents. I think in both cases, those variables are HTML strings - so if you know the values/content of those customfield lines, then you might get away with just using a string replace on them; if not, you might need to explode them into an array and remove these fields that way. Hey Brian!, Do you ever do any WHMCS dev work for hire (unrelated to this thread)? I tried to PM you... 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 18, 2021 Share Posted May 18, 2021 11 minutes ago, SeanP said: Do you ever do any WHMCS dev work for hire (unrelated to this thread)? I tried to PM you... the mailbox was full - try again. 0 Quote Link to comment Share on other sites More sharing options...
SeanP Posted May 19, 2021 Author Share Posted May 19, 2021 12 hours ago, brian! said: the mailbox was full - try again. PM sent... 0 Quote Link to comment Share on other sites More sharing options...
SeanP Posted May 25, 2021 Author Share Posted May 25, 2021 On 5/18/2021 at 11:04 AM, brian! said: the mailbox was full - try again. Did you get my PM? Let me know, if you are interested. 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.