-
-
Save craigedmonds/b65c65e02fd40bd381bf023ffef2c80e to your computer and use it in GitHub Desktop.
| <?php | |
| /* | |
| This script will allow you to send a custom email from anywhere within wordpress | |
| but using the woocommerce template so that your emails look the same. | |
| Created by [email protected] on 27th of July 2017 | |
| Put the script below into a function or anywhere you want to send a custom email | |
| */ | |
| function get_custom_email_html( $order, $heading = false, $mailer ) { | |
| $template = 'emails/my-custom-email-i-want-to-send.php'; | |
| return wc_get_template_html( $template, array( | |
| 'order' => $order, | |
| 'email_heading' => $heading, | |
| 'sent_to_admin' => false, | |
| 'plain_text' => false, | |
| 'email' => $mailer | |
| ) ); | |
| } | |
| // load the mailer class | |
| $mailer = WC()->mailer(); | |
| //format the email | |
| $recipient = "[email protected]"; | |
| $subject = __("Hi! Here is a custom notification from us!", 'theme_name'); | |
| $content = get_custom_email_html( $order, $subject, $mailer ); | |
| $headers = "Content-Type: text/html\r\n"; | |
| //send the email through wordpress | |
| $mailer->send( $recipient, $subject, $content, $headers ); |
This is very useful, but for some reason the following "standard" emails sent from woocommerce keep repeating this custom one, how would it be possible to - escape - this email?
Thanks in advance
You're Awesome!
is it possible to show here $subject = __("Hi! Here is a custom notification from us!", 'theme_name'); product short description ?
Great! Thank you for this code!
This code saved me a lot of headaches, thank you!!
Just what I was looking for. Thanks for sharing!
I know this has been here for ages, but I want to store the template in a plugin folder instead of the woocommerce folder, does anyone know how this is possible to do?
Whenever I try to do it, there will be an error because the plugin is expecting the template to be stored in the WooCommerce folder and no where else.
@FluxCoder, have your resolved the problem? I need to send emails from my own plugin using WC email template. I cannot find how to do it.
Thank you!