how i display custom field for mail admin woocommerce code example

Example: Woocommerce Display Custom Field value on the Email [Custom Field Display 3]

/**
 * Display field value on the Email..
 * source https://rudrastyh.com/woocommerce/order-meta-in-emails.html
 * PHP Custom Feild Value
 * @param $order_obj Order Object
 * @param $sent_to_admin If this email is for administrator or for a customer
 * @param $plain_text HTML or Plain text (can be configured in WooCommerce > Settings > Emails) 
 * 
 */
add_action( 'woocommerce_email_order_meta', 'misha_add_email_order_meta', 10, 3 );
function misha_add_email_order_meta( $order_obj, $sent_to_admin, $plain_text ){
 
  // ok, if it is the gift order, get all the other fields
  $gift_wrap = get_post_meta( $order_obj->get_order_number(), 'My Field', true );
 

 
    // you shouldn't have to worry about inline styles, WooCommerce adds them itself depending on the theme you use
    echo '<h2>Store Location</h2>
    <ul>
    <li><strong>Your Store Location is:</strong> ' . $gift_wrap . '</li>
    </ul>';

}

Tags:

Misc Example