Let’s say you have already styled your WooCommerce email and want to use the same email design for a custom email, how will you go about that? Turns out its pretty easy. For the sake of simplicity , I am assuming you have the needed data in variables, change them accordingly as per your code.
For instance, right now, your email function looks something like this:
$email = 'ashfame@example.com';
$subject = 'Custom stuff email';
$email_content = ''; // whatever it is
wp_mail( $email, $subject, $email_content );
Now, do the following and it will pull the email design in use with WooCommerce emails even if you haven’t styled it.
$email = 'ashfame@example.com';
$subject = 'Custom stuff email';
$email_heading = 'Custom Heading';
$email_content = ''; // whatever it is
ob_start();
do_action( 'woocommerce_email_header', $email_heading );
echo $email_content; // or simply have HTML markup outside PHP tags here
$email_content = ob_get_clean();
wp_mail( $email, $subject, $email_content );
The magic happens by calling in header and footer markup of WooCommerce emails along with the actual content, buffer the output it and pass that on to mail function.
2 comments
not working………..
My colleagues were looking for a form some time ago and encountered a document management site with a lot of fillable forms . If you need it too , here’s
http://goo.gl/xa0G4n