Hi again,
I solved this by doing the following:
Add to functions.php:
function preview_email()
{
$orderId = 914;
$email_class = 'WC_Email_New_Order';
$wc_emails = new WC_Emails();
$emails = $wc_emails->get_emails();
$new_email = $emails[$email_class];
$new_email->trigger($orderId);
echo $new_email->get_content();
return null;
}
add_action('wp_ajax_previewemail', 'preview_email');
call in browser:
https://yousite.com/wp-admin/admin-ajax.php?action=previewemail
There are important variables in the preview_email function:
$orderId => put here an orderId from you order database
$email_class => put here the email template you want to preview.
choose one of the template files:
WC_Email_Customer_Note
WC_Email_Customer_Completed_Order
WC_Email_Customer_New_Account
WC_Email_Customer_Reset_Password
WC_Email_Customer_Processing_Order
WC_Email_Customer_Invoice
WC_Email_New_Order
If you don’t want to make changes in the function, you can also so something like this:
https://yousite.com/wp-admin/admin-ajax.php?action=previewemail&mail=WC_Email_New_Order&order=914
In this case preview_emails function will be:
function preview_email()
{
$orderId = $_GET['order'];
$email_class = $_GET['mail'];
$wc_emails = new WC_Emails();
$emails = $wc_emails->get_emails();
$new_email = $emails[$email_class];
$new_email->trigger($orderId);
echo $new_email->get_content();
return null;
}
add_action('wp_ajax_previewemail', 'preview_email');