WP Better Emails
[resolved] Can This be Used with Woocommerce Email Templates? (4 posts)

  1. samandella
    Posted 2 years ago #


    This seems to be a good solution to the ugly Woocommerce emails. Can this be used to beautify those if I choose that the Woocommerce are plain (not html)?



  2. hellonico
    Plugin Author

    Posted 2 years ago #


    I'd say yes but I'm not sure Woocommerce lets you choose plain text.
    Have a look at this topic :

  3. BBIndikator
    Posted 2 years ago #

    Yes, it works with WooCommerce. Go to WooCommerce Settings (actual version) and set every Email to "send as plain text", and it will works..

  4. doublesharp
    Posted 2 years ago #

    @samandella, @hellonico, @BBIndikator

    I was struggling with this for a while - initially I selected "plain/text" for all of the WooCommerce emails, but the emails definitely lost style points. Then I dug a bit deeper into the code and figured out a way to hide the WooCommerce email headers, have WPBE not use the functions that break the HTML because the content type is "text/html", and then hook into "phpmailer_init" after WPBE to selectively apply the template to WooCommerce HTML formatted emails. I'm using create_function() but you could also use anonymous functions.

    I wrote it up on my website here: http://justin.ag/technology/wordpress/using-wp-better-emails-woocommerce-email-templates/

    // Determine if it's an email using the WooCommerce email header
    add_action( 'woocommerce_email_header', create_function( false, 'add_filter( "better_wc_email", "__return_true" );'), 1 );
    // Hide the WooCommerce Email header and footer
    add_action( 'woocommerce_email_header', create_function( false, 'ob_start();'), 1 );
    add_action( 'woocommerce_email_header', create_function( false, 'ob_get_clean();'), 100 );
    add_action( 'woocommerce_email_footer', create_function( false, 'ob_start();'), 1 );
    add_action( 'woocommerce_email_footer', create_function( false, 'ob_get_clean();'), 100 );
    // Selectively apply WPBE template if it's a WooCommerce email
    function better_phpmailer_init( $phpmailer ){
        if ( apply_filters( 'better_wc_email', false ) ){
            global $wp_better_emails;
            // Add template to message
            $phpmailer->Body = $wp_better_emails->set_email_template( $phpmailer->Body );
            // Replace variables in email
            $phpmailer->Body = apply_filters( 'wpbe_html_body', $wp_better_emails->template_vars_replacement( $phpmailer->Body ) );
    add_action( 'phpmailer_init', 'better_phpmailer_init', 20 );

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP Better Emails
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic