Skip to content

Instantly share code, notes, and snippets.

@mklasen
Last active February 21, 2017 09:31
Show Gist options
  • Save mklasen/a39a2073300fcabddda5599018ac5005 to your computer and use it in GitHub Desktop.
Save mklasen/a39a2073300fcabddda5599018ac5005 to your computer and use it in GitHub Desktop.
Use Woocommerce's email function and templates to send e-mails
<?php
function my_email_function($email, $header, $content) {
// We'll use Woocommerce e-mail function to send e-mail to users
ob_start();
// Get WC e-mail header
do_action( 'woocommerce_email_header', $header, $email );
// Content
echo $content;
// Get WC e-mail footer
do_action( 'woocommerce_email_footer', $email );
// Get output
$output = ob_get_contents();
ob_end_clean();
// Send e-mail
wc_mail( $email, $header, $output, $headers = "Content-Type: text/htmlrn", $attachments = "" );
}
// Usage
my_email_function('[email protected]', 'Your text in header', 'Your text in content. <a href="/my-account/">Click here</a>.');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment