Instantly share code, notes, and snippets.

Embed
What would you like to do?
WooCommerce - A filter to add a tracking (or any other field for that matter) to order emails to customers.
/* To use:
1. Add this snippet to your theme's functions.php file
2. Change the meta key names in the snippet
3. Create a custom field in the order post - e.g. key = "Tracking Code" value = abcdefg
4. When next updating the status, or during any other event which emails the user, they will see this field in their email
*/
add_filter('woocommerce_email_order_meta_keys', 'my_custom_order_meta_keys');
function my_custom_order_meta_keys( $keys ) {
$keys[] = 'Tracking Code'; // This will look for a custom field called 'Tracking Code' and add it to emails
return $keys;
}
@Ramoonus

This comment has been minimized.

Show comment
Hide comment
@Ramoonus

Ramoonus Jan 2, 2012

include in core?

Ramoonus commented Jan 2, 2012

include in core?

@Obka

This comment has been minimized.

Show comment
Hide comment
@Obka

Obka Aug 14, 2015

hi every body
i can't use this code
after i user this code in function.php i receive an FATAL ERROR
how can i fix this problem ?
thank

Obka commented Aug 14, 2015

hi every body
i can't use this code
after i user this code in function.php i receive an FATAL ERROR
how can i fix this problem ?
thank

@ShadowShape

This comment has been minimized.

Show comment
Hide comment
@ShadowShape

ShadowShape Apr 11, 2016

So simpel.. So effective, this is what i've been looking for. Thank you so much!
Is there any way to add css/html to the 'Tracking Code'?

ShadowShape commented Apr 11, 2016

So simpel.. So effective, this is what i've been looking for. Thank you so much!
Is there any way to add css/html to the 'Tracking Code'?

@Garconis

This comment has been minimized.

Show comment
Hide comment
@Garconis

Garconis Sep 5, 2017

How do you add a custom order field to the text within the customer_completed_order email?

Garconis commented Sep 5, 2017

How do you add a custom order field to the text within the customer_completed_order email?

@Quigley-Brendan

This comment has been minimized.

Show comment
Hide comment
@Quigley-Brendan

Quigley-Brendan Jan 19, 2018

How would I change the label? Currently in the email it shows the custom field as the label. Can I customize that without changing the custom field?

I see now. Just write something in $keys['Label']

Quigley-Brendan commented Jan 19, 2018

How would I change the label? Currently in the email it shows the custom field as the label. Can I customize that without changing the custom field?

I see now. Just write something in $keys['Label']

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