Forked from craigedmonds/woocommerce-send-custom-email-using-woo-template.php
Created
September 6, 2019 22:21
-
-
Save fahdi/b7446a057c3cd3b12cae52b8645d4043 to your computer and use it in GitHub Desktop.
This file contains 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 craig@123marbella.com 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 = "someone@somewhere.com"; | |
$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