Supposedly, this is what the wc_mail()
function is supposed to do: help you send an email the way you might with wp_mail()
BUT include your fancy WooCommerce template/design/styles around the content.
Well, it didn’t seem to be working for us, so after breaking it apart, we took the core function and wrote what we think should happen. It seems the key was adding line 15 here – the wrap_message()
function.
Seems to be working so far, so I’m posting it here in case anyone is trying to send custom emails that bring in the WooCommerce template/design from their shop.
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 | |
/** | |
* Our custom alternative to wc_mail. | |
* | |
* @param mixed $to Receiver. | |
* @param mixed $subject Subject. | |
* @param mixed $message Message. | |
* @param string $headers Headers. (default: "Content-Type: text/html\r\n"). | |
* @param string $attachments Attachments. (default: ""). | |
* @return bool | |
*/ | |
function prefix_mail( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = "" ) { | |
if( ! class_exists( 'WC_Emails' ) ) { include_once WC_ABSPATH . 'includes/class-wc-emails.php'; } | |
$mailer = WC()->mailer(); | |
$message = $mailer->wrap_message( $subject, $message ); | |
return $mailer->send( $to, $subject, $message, $headers, $attachments ); | |
} |
Leave a Reply