Last active
March 23, 2019 02:49
-
-
Save reandimo/1c6f359d331c1ac060915afb73038166 to your computer and use it in GitHub Desktop.
Woocommerce, wrap any content in the woocommerce default template of your store.
This file contains hidden or 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 | |
/** | |
* 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 <[email protected]> | |
*/ | |
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