// Add custom fields to woocommerce order emails
function action_woocommerce_email_customer_details( $order, $sent_to_admin, $plain_text, $email ) {
if ( $sent_to_admin ) { //add to admin email only
echo '<p><strong>Warehouse Location</strong>';
$items = $order->get_items();
foreach ( $items as $item ) {
$product_id = $item->get_product_id();
$product_name = $item->get_name();
$location = get_field( 'location', $product_id );
if( $location ){
echo '<p>' . $product_name . ' - ' . $location . '</p>';
}
}
}
};
add_action( 'woocommerce_email_customer_details', 'action_woocommerce_email_customer_details', 10, 4 );