I have a custom field for a Woocommerce’s product, and I want to display it’s value in order emails.

As I’m using custom product submission form, I added this code for custom field below to create a custom field:

    WCVendors_Pro_Form_Helper::select( array(  
        'post_id'       => $object_id,
        'class'         => 'select2',
        'id'            => 'wcv_custom_product_ingredients', 
        'label'         => __( 'What time?', 'wcvendors-pro' ), 
        'placeholder'   => __( 'Pick a time', 'wcvendors-pro' ),
        'wrapper_start' => '<div class="all-100">',
        'wrapper_end'   => '</div>',
        'desc_tip'      => 'true', 
        'description'   => __( 'Pick a time', 'wcvendors-pro' ),
        'options'       => array( '12:00 midnight' => __('12:00 midnight', 'wcv_custom_product_ingredients'), '12:15 midnight'=> __('12:15 midnight', 'wcv_custom_product_ingredients') )
) );

I also tried adding code below to functions.php, but this only displays “What time?” without value in order emails…

add_action('woocommerce_email_after_order_table', 'wcv_ingredients_email');
function wcv_ingredients_email() {
    $output = get_post_meta( get_the_ID(), 'wcv_custom_product_ingredients', true );
    echo 'What time? ' . $output . '<br>';

What could be the issue?

Read more here: Output product custom field value in order email notification


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: