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>';

}

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source