How to preview email templates of Woocommerce

email, php, templates, woocommerce, wordpress

Solution

I ended up creating a small function which is executed via the admin-ajax.php script, e.g.

https://example.org/wp-admin/admin-ajax.php?action=previewemail&file=emails/customer-processing-order.php&order=180

The function:

- sets the global `$order` variable to the order with the id specified in the `order` parameter

- load the email template specified in the `file` parameter.

This is the code (you must add it a new plug-in or in some existing php):

/**
 * Open a preview e-mail.
 *
 * @return null
 */
function preview_email()
{
    global $order;

    $filename = $_GET['file'];
    $orderId  = $_GET['order'];

    $order    = new WC_Order($orderId);

    include $filename;

    return null;
}

add_action('wp_ajax_previewemail', 'preview_email');    

Problem

I can't seem to find an option to preview the different e-mail templates of Woocommerce. In the admin section of Woocommerce there is a link to preview the "Order recieved" email for customers. But I would like to edit and preview the "Order recieved" email sent to the admin. I have tried WP Better emails plugin and the WP email template plugins but they didn't offer a preview button for all the different emails of Woocommerce. Previewing the email templates by placing orders isn't an option because there's a lag of ten minutes between placing the order and recieving the admin email.

Original source