Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to preview email templates of Woocommerce

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.

like image 795
ferencvandervelde Avatar asked Feb 21 '13 16:02

ferencvandervelde


People also ask

How do I find my email template in WooCommerce?

WooCommerce Email Templates Overview Basically, go into the woocommerce folder and navigate to the `templates` sub-folder. Inside there you'll see another sub-folder called `emails`. You can grab any and all of those files, and copy them (don't “move”) into your theme folder into `woocommerce\emails`.

How do I use WooCommerce email templates?

Start by installing the extension from your WordPress dashboard, just as you would any other plugin. Then: Go to MailPoet → Settings → WooCommerce in your WordPress dashboard, select Use MailPoet to Customize Your WooCommerce Emails and save your settings. Click Open Template Editor.

Where are WordPress email templates stored?

Template files are located within the /wp-content/plugins/woocommerce/templates/ directory.

How do I override WooCommerce email templates?

If you go to a particular option in WooCommerce Email Settings, for example 'Processing Order', you will notice a message. To override and edit this email template copy {file-path} to your theme folder: {theme/file-path}. This method allows you a more advanced option to customize WooCommerce order emails.


1 Answers

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');    
like image 84
David Riccitelli Avatar answered Nov 03 '22 01:11

David Riccitelli