Add a custom field (in an order) to the emails (4 posts)

  1. simmonsstummer
    Posted 2 years ago #

    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;


  2. Daniel Espinoza
    Posted 2 years ago #

    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: https://gist.github.com/ChromeOrange/3905785

    Try removing that key and give it another try.

  3. simmonsstummer
    Posted 2 years ago #

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

  4. Daniel Espinoza
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic