Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Shahram Martin Rezazadeh
Shahram Martin Rezazadeh
5,328 Points

Woocommerce problem: can't get custom fields from checkout on my order mail or invoice mail?

So what I need is to get my custom field like "child_age" (the fields are made with the woocommerce custom field addon) on the order mail or invoice mail.

This is the documentation site but it won't show up.

https://docs.woocommerce.com/document/add-a-custom-field-in-an-order-to-the-emails/

it says Copy the following code to your theme functions.php

add_filter( 'woocommerce_email_order_meta_fields', 'custom_woocommerce_email_order_meta_fields', 10, 3 );

function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) { $fields['meta_key'] = array( 'label' => __( 'Label' ), 'value' => get_post_meta( $order->id, 'meta_key', true ), ); return $fields; }

so should U copy this in my actual function.php with editor?

and than

Using this example the code would be:

$fields['How did you hear about us?'] = 'hear_about_us';

it says.

I'm really confused I'm still a noob in PHP

thanks for you help