Invoke custom meta order in woocommerce email

I have custom fields at the box office in woocommerce and I want these fields to appear in the email template.

I am adding the following, but it is not yet displayed:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); $mycustom = get_post_meta( $order->id, 'wccf_delivery_day', true ); echo $mycustom;?> <?php endwhile; ?> 
+5
source share
1 answer

You can use woocommerce_email_order_meta_keys hook hook

 add_filter('woocommerce_email_order_meta_keys', 'my_woocommerce_email_order_meta_keys'); function my_woocommerce_email_order_meta_keys( $keys ) { $keys['Delivery Day'] = '_wccf_delivery_day'; return $keys; } 

If you need more control over the display, try using the woocommerce_email_after_order_table action hook

 add_action( "woocommerce_email_after_order_table", "custom_woocommerce_email_after_order_table", 10, 1); function custom_woocommerce_email_after_order_table( $order ) { echo '<p><strong>Delivery Day :</strong>'. get_post_meta( $order->id, "_wccf_delivery_day", true ) .'</p>'; } 
+7
source

Source: https://habr.com/ru/post/1233224/


All Articles