Make Woocommerce (3.8.0) admin email include my custom field data from the checkout page

Solution:

WordPress has an option to turn on debug mode, so that errors and warnings can be identified and resolved. Errors will be logged in a file named debug.log in the wp-content folder of the WordPress folder while your code make any errors. So while developing in WordPress, you have to turn on three options. Goto wp-config.php and add these three lines of code

define('WP_DEBUG', true);
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );

your custom_woocommerce_email_order_meta_fields function has an error. You called order id incorrectly. The error log will show that. Order properties shouldn’t be called directly. So you have to change $order->id to $order->get_id(). So change the function to

function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
    if( !$sent_to_admin ){
        return;
    }
    $fields['custom_field_1'] = array(
        'label' => __( 'custom field 1' ),
        'value' => get_post_meta( $order->get_id(), 'custom_field_1', true ),
    );
    $fields['custom_field_2'] = array(
        'label' => __( 'custom field 2' ),
        'value' => get_post_meta( $order->get_id(), 'custom_field_2', true ),
    );
    $fields['custom_field_3'] = array(
        'label' => __( 'custom field 3' ),
        'value' => get_post_meta( $order->get_id(), 'custom_field_3', true ),
    );
    $fields['custom_field_4'] = array(
        'label' => __( 'custom field 4' ),
        'value' => get_post_meta( $order->get_id(), 'custom_field_4', true ),
    );
    return $fields;
}

Also you haven’t written any code to save the custom fields you added to checkout page. You are trying to find the values that aren’t saved in the order meta. You need to write the code to save the custom added checkout fields to the order meta as below.

add_action('woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta');
function my_custom_checkout_field_update_order_meta( $order_id ) {
    if ($_POST['custom_field_1']) update_post_meta( $order_id, 'custom_field_1', esc_attr($_POST['custom_field_1']));
    if ($_POST['custom_field_2']) update_post_meta( $order_id, 'custom_field_2', esc_attr($_POST['custom_field_2']));
    if ($_POST['custom_field_3']) update_post_meta( $order_id, 'custom_field_3', esc_attr($_POST['custom_field_3']));
    if ($_POST['custom_field_4']) update_post_meta( $order_id, 'custom_field_4', esc_attr($_POST['custom_field_4']));
}

Done . . . Now everything is added perfectly to the email (tested and confirmed). Also since you have said these fields are shown in the admin emails, you have to check that condition using

if( !$sent_to_admin ){
   return;
}

which i have added in the custom_woocommerce_email_order_meta_fields function.