Support » Plugin: Email Template Designer - WP HTML Mail » Limit these emails to only one kind?
Limit these emails to only one kind?
-
Hi,
I did read your notes on excluding HTML designs being applied to Woo emails and what not; but is there a way to apply them to ONLY a certain type of email? Kinda like an opposite function of what you created? basically, I only want the HTML designs to be applied to emails sent from Uncanny Automator. Everything else is totally fine and I don’t want it to conflict with FluentCRM and Woo etc…
-
Hey @shayno90
Yes you can use the same filter. Is there anything all your Automator mails have in common? Maybe part of the content or part of the subject?Hi Hannes!
Hmm.. I guess I could find something they have in common… For example, the subject line will always include “Your edits are ready”. So, basically, I would just need your plugin to apply to only those with that subject line
Is that possible?
Hi,
I just cannot get your filter to work in the way I had hoped 🙁 Are you able to help out? The goal is to apply the HTML emails only to those emails with a subject of “XYZ”. I am using FluentCRM as a marketing tool and therefore can’t keep adding in subject lines to the code to avoid the template being applied.Thanks so much!
Hello @shayno90
Use this code snippet to only use the template for emails containing “XYZ” in subject:add_filter( 'haet_mail_use_template', function( $use_template, $mail ){ return strpos( $mail['subject'], 'XYZ' ) !== false; }, 10, 2 );
Thank you so much Hannes! Works flawlessly!
Oh, sorry – just a quick one; If I needed to add more email subjects, is this the right way to do it?
add_filter( 'haet_mail_use_template', function( $use_template, $mail ){ return strpos( $mail['subject'], 'Your edits & video are ready!' ) !== false; return strpos( $mail['subject'], 'Please upload your photos' ) !== false; }, 10, 2 );
Thanks!
No please try like that:
add_filter( 'haet_mail_use_template', function( $use_template, $mail ){ return strpos( $mail['subject'], 'Your edits & video are ready!' ) !== false || strpos( $mail['subject'], 'Please upload your photos' ) !== false || strpos( $mail['subject'], 'another subject' ) !== false; }, 10, 2 );
I actually tested this way here and it works:
add_filter( 'haet_mail_use_template', function( $use_template, $mail ){ return strpos( $mail['subject'], 'Your edits & video are ready!', 'Please upload your photos', 'Your Mentoring Session', 'Password Reset', 'Password Changed', 'Email Changed', 'Some plugins', 'Login Details', 'New User Registration', 'Your Site is Experiencing a Technical Issue' ) !== false; }, 10, 2 );
But is your way better?
I didn’t know strpos() can handle multiple search terms. I also can’t find anything in the function documentation.
I’m honestly not sure why your code even works. 😉I just tried your code and followed what you did but I keep getting an error 🙁
Uncaught Error: Object of class WP_Error could not be converted to string in /home/customer/www/rootspresets.com/public_html/wp-content/plugins/sg-security/templates/error.php:111 Stack trace: #0 /home/customer/www/rootspresets.com/public_html/wp-content/plugins/sg-security/core/Helper/Helper.php(111): include() #1 /home/customer/www/rootspresets.com/public_html/wp-includes/functions.php(3661): SG_Security\Helper\Helper->custom_wp_die_callback(Object(WP_Error), '', Array) #2 /home/customer/www/rootspresets.com/public_html/wp-includes/class-wp-fatal-error-handler.php(233): wp_die(Object(WP_Error), '', Array) #3 /home/customer/www/rootspresets.com/public_html/wp-includes/class-wp-fatal-error-handler.php(152): WP_Fatal_Error_Handler->display_default_error_template(Array, Object(WP_Error)) #4 /home/customer/www/rootspresets.com/public_html/wp-includes/class-wp-fatal-error-handler.php(57): WP_Fatal_Error_Handler->display_error_template(Array, Object(WP_Error)) #5 [internal function]: WP_Fatal_Error_Handler->handle
This is the code I used:
add_filter( 'haet_mail_use_template', function( $use_template, $mail ){ return strpos( $mail['subject'], 'Your edits & video are ready!' ) !== false || strpos( $mail['subject'], 'Please upload your photos' ) !== false || strpos( $mail['subject'], 'Your Mentoring Session' ) !== false; || strpos( $mail['subject'], 'Password Reset' ) !== false; || strpos( $mail['subject'], 'Password Changed' ) !== false; || strpos( $mail['subject'], 'Email Changed' ) !== false; || strpos( $mail['subject'], 'Some plugins' ) !== false; || strpos( $mail['subject'], 'Login Details' ) !== false; || strpos( $mail['subject'], 'New User Registration' ) !== false; || strpos( $mail['subject'], 'Your Site is Experiencing a Technical Issue' ) !== false; }, 10, 2 );
Only the last of the strpos() lines should end with a semicolon “;”
Oh of course. Thank you so much! Will run some more tests!
Works an absolute charm! Thank you so much Hannes!
- The topic ‘Limit these emails to only one kind?’ is closed to new replies.