WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. samandella
    Member
    Posted 7 months ago #

    Hi

    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)?

    Thanks

    http://wordpress.org/plugins/wp-better-emails/

  2. hellonico
    Member
    Plugin Author

    Posted 6 months ago #

    Hello,

    I'd say yes but I'm not sure Woocommerce lets you choose plain text.
    Have a look at this topic :
    http://wordpress.org/support/topic/woocommerce-and-wp-better-emails?replies=4

  3. BBIndikator
    Member
    Posted 4 months 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
    Member
    Posted 46 minutes 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 );

Reply

You must log in to post.

About this Plugin

About this Topic