Add Order Meta to Emails
We already discussed on my blog how to add custom order meta to view order page or to order details metabox in WooCommerce admin. It is time to add the same custom fields to WooCommerce emails.
We are going to use primary woocommerce_email_order_meta
action hook for that. There is also another hook – woocommerce_email_order_meta_fields
, we will also take a look on it, but I recommend you the first one.
Method 1. woocommerce_email_order_meta
On the screenshot below you can see that the additional “Gift Information” section has been added. We already worked with these fields in posts I mentioned above.

If you add the code below to your functions.php
, the “Gift” section will be added mostly for all default WooCommerce emails, except “New Account” and “Reset Password” emails.
<?php
/**
* Add custom order meta to WooCommerce emails
*
* @author Misha Rudrastyh
* @link https://rudrastyh.com/woocommerce/order-meta-in-emails.html
*/
add_action( 'woocommerce_email_order_meta', 'misha_add_email_order_meta', 10, 3 );
function misha_add_email_order_meta( $order, $sent_to_admin, $plain_text ){
// this order meta checks if order is marked as a gift
$is_gift = $order->get_meta( 'is_gift' );
// we won't display anything if it is not a gift
if( empty( $is_gift ) ) {
return;
}
// ok, if it is the gift order, get all the other fields
$gift_wrap = esc_html( $order->get_meta( 'gift_wrap' ) );
$gift_recipient = esc_html( $order->get_meta( 'gift_name' ) );
$gift_message = esc_html( $order->get_meta( 'gift_message' ) );
// ok, we will add the separate version for plaintext emails
if ( false === $plain_text ) {
// you shouldn't have to worry about inline styles, WooCommerce adds them itself depending on the theme you use
?>
<h2>Gift Information</h2>
<ul>
<li><strong>Is gift?</strong> Yes</li>
<li><strong>Gift Wrap:</strong> <?php echo $gift_wrap ?></li>
<li><strong>Recipient name:</strong> <?php echo $gift_recipient ?></li>
<li><strong>Gift message:</strong> <?php echo wpautop( $gift_message ) ?></li>
</ul>
<?php
} else {
echo "\nGIFT INFORMATION\n"
. "Is gift: Yes\n"
. "Gift Wrap: $gift_wrap\n"
. "Recipient name: $gift_recipient\n"
. "Gift message: $gift_message\n";
}
}
Each WooCommerce email can be configured to be sent and displayed as a plain text email. Lines 27
and 40–48
in the above code are just for that.
The same email in plain text:

Method 2. woocommerce_email_order_meta_fields
If you look through official WooCommerce tutorials and some other tutorials over the internet, you will find out that people use woocommerce_email_order_meta_fields
and woocommerce_email_order_meta_keys
filter hooks.
First of all woocommerce_email_order_meta_keys
is deprecated since WooCommerce 2.3.0. woocommerce_email_order_meta_fields
seems ok, but it is less customizable that woocommerce_email_order_meta
, for example you can not add some custom HTML with it.
Example:

woocommerce_email_order_meta_fields
filter hook.But for plain text emails and some other email themes everything looks good. Anyway, I want to share the code with you:
add_filter('woocommerce_email_order_meta_fields', 'misha_add_email_meta', 10, 3 );
function misha_add_email_meta( $fields, $sent_to_admin, $order ) {
$is_gift = $order->get_meta( 'is_gift' );
// we won't display anything if it is not a gift
if( empty( $is_gift ) ) {
return $fields;
}
$fields[ 'is_gift' ] = array(
'label' => 'Is gift?',
'value' => 'Yes'
);
$fields[ 'gift_wrap' ] = array(
'label' => 'Gift Wrap',
'value' => $order->get_meta( 'gift_wrap' )
);
$fields[ 'gift_name' ] = array(
'label' => 'Recipient name',
'value' => $order->get_meta( 'gift_name' )
);
$fields[ 'gift_message' ] = array(
'label' => 'Gift message',
'value' => wpautop( $order->get_meta( 'gift_message' ) )
);
return $fields;
}
By the way, this filter can be useful when you want to unset()
some of fields that were set by a plugin.

Misha Rudrastyh
Hey guys and welcome to my website. For more than 10 years I've been doing my best to share with you some superb WordPress guides and tips for free.
Need some developer help? Contact me
Hi, thanks for your example, it looks great!
I have one question: In which e-mails will this meta-information be displayed? Are this all the e-mails that are sent to the shop admin and does this include subscription e-mails (cancellations, renewals, switches)?
Hi,
In all emails related to orders. But I recommend to test it, you can use plugins like Email Customizer to check it.
Hi,
Thanks for this tutorial!
However, this works in emails to customers, but not to admin.
Where do I need to change to make the email with “meta information” to admin as well?
Thank you,
Stonez
Hey,
How can I call that function for the field where_did_you_hear_about_us? I just added the code below in the file /public_html/wp-content/plugins/woocommerce/templates/emails/email-addresses.php
Hey,
The code must be added to your current theme
functions.php
(or child theme or custom plugin).Hey Misha thank you!
Yeah I found it later. Thank you!
Hi!
tried to hook in
woocommerce_email_order_meta
from my custom plugin but it doesn’t work! Same code infunctions.php
works fine. Any idea what i’m missing?Hi,
Please, try to use your hook inside the
init
hook. Example:Hi!
I would like to do something similar on my site.
I would like to add the “username” field in the order confirmation email. Do you know how to do it?
Hi
Thank you for the info but I’m a bit confused.
When someone places an order on our website, our payment gateway generates these two custom fields for every order:
Authentication Code
Payment date
When I go to each Processing or Completed order, I can see these custom fields in the bottom line.
I would like these to show up in the new order emails as well. What do I need to do?
can you please help?
Thank you
Thanks for your tutorial, Misha.
On my case, I just need to output 3 required custom fields into the order email and since they are required, I don’t need to check anythinig like your “is Gift” example.
The 3 custom fields are “billing_cnpj” (text), “billing_uf_cliente_final” (select) and “billing_imposto” (select).
Can you point me how can I extract those values (which are being saved into the database) to output it on the order email?
Any help is appreciated.
Hey,
Did you save your fields in order meta?
Hello Misha, sorry for the question, I am newbie dealing with woocommerce code.
In your example instead of using the gift_recipient I want to display billing_first_name. What I have to do?
Hello,
You can use
$order->get_billing_first_name()
Thank you very much
Bless you. tyvm