Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Nicolas Lemoine

    (@nlemoine)

    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

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

    @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 );
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Can This be Used with Woocommerce Email Templates?’ is closed to new replies.