WooCommerce E-Mail Customization

How can I edit the email content?

Activate WP HTML Mail as well as WP HTML Mail WooCommerce.

Navigate to Settings -> Email Template -> WooCommerce.

Switch the setting to “customize each email individually” and click the email you want to customize below.

How to add my own placeholder to the email editor?

If you want to add your own placeholder for dynamic values from orders to  your emails add this code to your (child-)themes functions.php:

add_filter( 'haet_mail_placeholder_menu', 'add_mailbuilder_placeholder' );
add_filter( 'haet_mail_order_placeholders', 'populate_mailbuilder_placeholder', 10, 3 );

function add_mailbuilder_placeholder( $placeholder_menu ){
    if( is_array( $placeholder_menu ) ){
        $placeholder_menu[] = array(
                'text'      => 'My Placholder Name',
                'tooltip'   => '[MY_PLACEHOLDER]',
            );
    }

    return $placeholder_menu;
}


function populate_mailbuilder_placeholder( $order, $wc_order, $settings ){
    $order['my_placeholder'] = 'your value';
    return $order;
}

The first function registers the placeholder, the second one adds a value.

Can I add the coupon code to the email text?

Yes, just register a placeholder like we did above and insert the coupons as value:

add_filter( 'haet_mail_placeholder_menu', 'add_mailbuilder_coupons_placeholder' );
add_filter( 'haet_mail_order_placeholders', 'populate_mailbuilder_coupons_placeholder', 10, 3 );
function add_mailbuilder_coupons_placeholder( $placeholder_menu ){
    if( is_array( $placeholder_menu ) ){
        $placeholder_menu[] = array(
                'text'      => 'Coupons',
                'tooltip'   => '[COUPONS]',
            );
    }
    return $placeholder_menu;
}

function populate_mailbuilder_coupons_placeholder( $order, $wc_order, $settings ){
    $coupons_text = '';
    if( $wc_order ){
        $coupons =  $wc_order->get_used_coupons();
        if( is_array( $coupons ) && count( $coupons ) ){
            $coupons_text .= 'You have used the following coupons: <br>';

            foreach( $coupons as $coupon_name ){

                // Retrieving the coupon ID
                $coupon_post_obj = get_page_by_title($coupon_name, OBJECT, 'shop_coupon');
                $coupon_id = $coupon_post_obj->ID;

                // Get an instance of WC_Coupon object in an array(necesary to use WC_Coupon methods)
                $coupons_obj = new WC_Coupon($coupon_id);
                $discount_type = $coupons_obj->get_discount_type();
                $amount_str = '';
                if( $discount_type == 'fixed_cart' )
                    $amount_str = '- €' . $coupons_obj->get_amount();
                elseif( $discount_type == 'percent' )
                    $amount_str = '- ' . $coupons_obj->get_amount() . '%';
                //elseif( $discount_type == ...
                
                $coupons_text .= '<strong>' . $coupons_obj->get_code() . '</strong>: ' . $amount_str . ', ';

            }
        }
    }
    $order['coupons'] = $coupons_text;
    return $order;
}