简体   繁体   中英

Woocommerce Email Custom field not display in table

I created a site in wordpress using woocommerce and i added custom fields in checkout page, also in email after the checkout.

But the problem is custom data (Delivery Method) field is not display under the table in email generated by woocommerce.

Please help me to solve this issue.

在此处输入图片说明

Here is my code

add_filter('woocommerce_email_order_meta_keys', 'my_woocommerce_email_order_meta_keys');

function my_woocommerce_email_order_meta_keys($keys)
{
    $keys['Delivery Method'] = 'delivery_options';
    return $keys;
}

Robin,

I have tried your problems one solution hope this will be usefull to you.

Solution I tried (And it worked for me)

/*This is action hook for adding content before the mail template footer*/
add_action( 'woocommerce_email_footer', 'custom_email_footer', 10, 1 );

function custom_email_footer( $email ) {
 /*$_POST['billing_delivery_date'] (My custom field variable)*/

 if (isset($_POST['billing_delivery_date'])) { /*Get value of the custom field*/

  /*Echo the filed value with some string or as you want*/
   echo "Delivery date : ".$_POST['billing_delivery_date'];
 }
}
  • Understanding

    There are several woo-commerce hooks available that can be used to add custom data to the email template sent by mail.

    NOTE: I also used one of them. :-)

Also The hook you are using will generate or add the custom field into the email template in the order as per the priority.

  • Screenshot 1

    Before used hook / while using your hook : 前图像

  • Screenshot 2

    After Using (woocommerce_email_footer) hook: 后图像

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM