How to use WooCommerce email design in custom emails

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 );
view raw before.php hosted with ❤ by GitHub

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 );
view raw after.php hosted with ❤ by GitHub

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.


Comments

2 responses to “How to use WooCommerce email design in custom emails”

  1. Amit Patra Avatar
    Amit Patra

    not working………..

  2. Earl Goolie Avatar
    Earl Goolie

    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

Leave a Reply

Your email address will not be published. Required fields are marked *