Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call custom order meta in woocommerce email

I have custom fields in the checkout in woocommerce and I want these fields to appear in the email template.

I am adding the following but it still not showing:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post();

            $mycustom = get_post_meta( $order->id, 'wccf_delivery_day', true );
            echo $mycustom;?>
            <?php endwhile; ?>
like image 525
user38208 Avatar asked Oct 08 '15 08:10

user38208


People also ask

How do I customize order Emails in WooCommerce?

You can customize the emails via your wp-admin > WooCommerce > Settings > Emails. Here you'll find the ability to customize all of the emails that WooCommerce sends both to you as a store admin, and to your customers.

How do I receive an order email from WooCommerce?

Double-check that “Enable this email notification” is ticked for order notifications at WooCommerce > Settings > Emails and select the Processing Order email template. An additional test should be setting the Email Type to plain text.


1 Answers

You can make use of woocommerce_email_order_meta_keys filter 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 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>';

}
like image 75
Anand Shah Avatar answered Sep 27 '22 02:09

Anand Shah