In Woocommerce, I need to print a custom field on the Completed Order email.
The template is completely unique in my themes woocommerce/emails folder because the default template doesn’t work for my needs.
As such I’m trying to display the following:
Title, Quantity and two custom fields
This needs to be included in the customer-completed-order.php email template but I am not certain what syntax is necessary to print it.
I found something by Googling but it doesn’t work:
<?php foreach ( $items as $item_id => $item ) :
$_product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
?>
<p>Class: <?php echo get_post_meta($_product->id,'name',true); ?></p>
<p>Date: <?php echo get_post_meta($_product->id,'date_text_field',true); ?></p>
<p>Time: <?php echo get_post_meta($_product->id,'time_text_field',true); ?></p>
<p>Number of Spaces: <?php echo get_post_meta($_product->id,'qty',true); ?></p>
<?php endforeach; ?>
Try adding to action hook,
do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order );
OR
do_action( 'woocommerce_order_item_meta_end', $item_id, $item, $order );
This could be used in following way:
OR
Following is the callback handler function.
Change the custom field names to appropriate. You might also need to wrap the output according to the required markup for your custom email.
Hope this helps.