Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save frank-liu/1e045fc6651f266a83d78b1d1e705b70 to your computer and use it in GitHub Desktop.
Save frank-liu/1e045fc6651f266a83d78b1d1e705b70 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 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