Support » Plugin: WooCommerce » Add a custom field (in an order) to the emails

  • Hi,
    i need to add the value of a custom field in the checkout to the mail i receive.

    this is what says the codex but does not show the value i need:

     * Add the field to order emails
    add_filter('woocommerce_email_order_meta_keys', 'my_woocommerce_email_order_meta_keys');
    function my_woocommerce_email_order_meta_keys( $keys ) {
    	$keys['How did you hear about us?'] = 'hear_about_us';
    	return $keys;

Viewing 3 replies - 1 through 3 (of 3 total)
  • The code that uses the woocommerce_email_order_meta_keys filter is in

    Here it is:

    if ( $show_fields )
                            foreach ( $show_fields as $key => $field ) {
                                     if ( is_numeric( $key ) )
                                             $key = $field;
                                     $meta[ wptexturize( $key ) ] = wptexturize( get_post_meta( $order->id, $field, true ) );

    You’ll see it’s checking that the $key is numeric. Your key is ‘How did you hear about us?’ and is not numeric.

    The original gist is here:

    Try removing that key and give it another try.

    how can i ovveride that code without editing the class-wc-emails.php?

    You shouldn’t override core code. The gist shows how to hook in with an action and use a filter. The core code is written in a way that allows it to be extended in this way.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add a custom field (in an order) to the emails’ is closed to new replies.