You can use a custom function hooked in any of this hooks (tuning the hook priority):
- woocommerce_email_order_details
- woocommerce_email_order_meta
- woocommerce_email_customer_details
Here it is an example of hooked code (instead of overriding the template):
add_action ('woocommerce_email_customer_details', 'custom_email_customer_details', 15, 4);
function custom_email_customer_details( $order, $sent_to_admin, $plain_text, $email ){
// Only for "New Order" email notification
if ( 'new_order' != $email->id ) return;
// Only "Flat Rate" Shipping Method
if ( $order->has_shipping_method('flat_rate') ){
$order_id = $order->get_id(); // The Order ID
// Test output
echo "<p>Message: The Order ID is $order_id</p>";
echo '<p>Custom field: '. get_post_meta( $order_id, '_recorded_sales', true ) .'</p>';
}
}
The hook priority here is 15, so it comes after the customer details.
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested and works.