docs/features/email/email-preview.md
WooCommerce's Email Preview feature allows you to preview email templates using dummy data (i.e., it doesn't use the actual data from the database). This means that extensions registering new email types need to integrate with the email preview system to properly showcase their emails.
The following hooks allow extensions to take full control of email preview:
These hooks allow extensions to add new style and content settings that the email preview listens for changes, and updates the preview when changes are made.
woocommerce_email_preview_email_style_setting_idsAdd new email style settings that the email preview listens for changes.
add_filter( 'woocommerce_email_preview_email_style_setting_ids', function( $setting_ids ) {
$setting_ids[] = 'my_extension_email_style';
return $setting_ids;
} );
woocommerce_email_preview_email_content_setting_idsAdd new email content settings that the email preview listens for changes.
add_filter( 'woocommerce_email_preview_email_content_setting_ids', function( $setting_ids ) {
$setting_ids[] = 'my_extension_email_content';
return $setting_ids;
} );
woocommerce_email_preview_dummy_orderModify the dummy WC_Order object used in preview.
add_filter( 'woocommerce_email_preview_dummy_order', function( $order ) {
// Modify the dummy order object
$order->set_currency( 'EUR' );
return $order;
} );
woocommerce_email_preview_dummy_productModify the dummy product used in preview.
add_filter( 'woocommerce_email_preview_dummy_product', function( $product ) {
// Modify the dummy product object
$product->set_name( 'My Product' );
return $product;
} );
woocommerce_email_preview_dummy_product_variationModify the dummy product variation used in preview.
add_filter( 'woocommerce_email_preview_dummy_product_variation', function( $variation ) {
// Modify the dummy variation object
$variation->set_name( 'My Variation' );
return $variation;
} );
woocommerce_email_preview_dummy_addressModify the dummy address used in preview.
add_filter( 'woocommerce_email_preview_dummy_address', function( $address ) {
// Modify the dummy address array
$address['first_name'] = 'Preview';
$address['last_name'] = 'Customer';
return $address;
} );
woocommerce_email_preview_placeholdersModify placeholders to be replaced in the email.
add_filter( 'woocommerce_email_preview_placeholders', function( $placeholders ) {
// Add custom placeholders
$placeholders['{custom_placeholder}'] = 'Custom Value';
return $placeholders;
} );
woocommerce_prepare_email_for_previewModify the WC_Email object used in preview.
add_filter( 'woocommerce_prepare_email_for_preview', function( $email ) {
// Modify the email object, e.g. to replace WC_Order
$email->set_object( $custom_object );
return $email;
} );
When integrating with email preview:
Use Appropriate Object Types
WC_Subscription instead of WC_Order for WooCommerce Subscriptions)Handle Placeholders
Style and Content Settings
Testing
Common issues and solutions:
I see "There was an error rendering an email preview." error
class-wc-admin.php and remove try/catch block around rendering the email preview to see the error message.Style or Content Settings Changes Not Reflecting
woocommerce_email_preview_email_style_setting_ids filterwoocommerce_email_preview_email_content_setting_ids filterI don't see my extension's emails
woocommerce_email_classes filter