Forked from craigedmonds/woocommerce-send-custom-email-using-woo-template.php
Created
October 1, 2018 14:59
-
-
Save frank-liu/1e045fc6651f266a83d78b1d1e705b70 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment