Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reandimo/1c6f359d331c1ac060915afb73038166 to your computer and use it in GitHub Desktop.
Save reandimo/1c6f359d331c1ac060915afb73038166 to your computer and use it in GitHub Desktop.
Woocommerce, wrap any content in the woocommerce default template of your store.
<?php
/**
* Wrap any content in the WooCommerce default email template of your store, for any use. Get the heading, message and footer to send.
* @author Renan Diaz <reandimo23@gmail.com>
*/
function wrap_email_content( $heading = null, $message = null ) {
if ( $message !== null && !empty($message) ) {
// load the mailer class
$mailer = WC()->mailer();
// create a new email
$email = new WC_Email();
$email_heading = ( !empty( $heading ) ) ? $heading : get_option( $this->option_name . '_default_heading' ) ;
$message = do_shortcode( $message );
// wrap the content with the email template and then add styles
$output = apply_filters( 'woocommerce_mail_content', $email->style_inline( $mailer->wrap_message( $email_heading, $message ) ) );
return $output;
}else{
return false;
}
}
$message = 'Some content <even with shortcodes>';
$content = wrap_email_content( 'Heading Example', $message );
// load the mailer class
$mailer = WC()->mailer();
//recipients list
$recipient = array('email1', 'email2');
//Headers
$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