Skip to content

Instantly share code, notes, and snippets.

@woogist
Created September 29, 2014 09:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save woogist/c3c13c03a1fdc4b9c823 to your computer and use it in GitHub Desktop.
Save woogist/c3c13c03a1fdc4b9c823 to your computer and use it in GitHub Desktop.
WooCommerce - add extra checkout fields to WooCommerce emails
<?php
/**
* Add the field to order emails
**/
add_filter('woocommerce_email_order_meta_keys', 'my_custom_checkout_field_order_meta_keys');
function my_custom_checkout_field_order_meta_keys( $keys ) {
$keys[] = 'My Field 1';
$keys[] = 'My Field 2';
return $keys;
}
@helgatheviking
Copy link

I would adjust this to:

/**
 * Add the field to order emails
 **/
add_filter('woocommerce_email_order_meta_keys', 'my_custom_checkout_field_order_meta_keys');

function my_custom_checkout_field_order_meta_keys( $keys ) {
    $keys['My Field 1'] = '_my_field_1;
    $keys['My Field 2'] = '_my_field_2';
    return $keys;
}

As this produces a more readable result:

My Field 1: Some value
My Field 2: Another value

instead of

_my_field_1: Some value
_my_field_2: Another value

@AdamChlan
Copy link

Are there any version requirements for this? I'm running on 2.1.12 and my custom fields are not coming over in the email.

@Tiaaas
Copy link

Tiaaas commented Nov 7, 2014

I have the same problem. Does not receive the cutom fields in the email.

@capecodder90
Copy link

It is so good to know I'm not the only one who cannot get this to work. I've been thinking I'm going nuts for the last hour.

@elkano91
Copy link

elkano91 commented Jun 20, 2016

Hello everybody ! I found this post on Github https://gist.github.com/ChromeOrange/3905785 and it solved my problem: my custom fields are now displaying in the email. I just needed to leave the key empty: $keys[]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment