产品电子邮件中包含的woocommerce自定义字段

时间:2022-05-26 08:07:14

I'm trying to include a custom field in the email that is sent to customers upon purchase. I added a custom field "Phone_number" into the all of the product pages.

我正在尝试在购买时发送给客户的电子邮件中包含自定义字段。我在所有产品页面中添加了一个自定义字段“Phone_number”。

I've tried including

我试过包括

 <?php
 $orderidno = $order->id;
 $prodmetaa = get_post_meta($orderidno, "Phone_number" , True);
 echo $prodmetaa;
 ?>

In the order email template, but haven't had any success. Has anyone done anything like this before or have any Idea how I could accomplish this .

在订单电子邮件模板中,但没有取得任何成功。有没有人之前做过这样的事情或有任何想法我怎么能做到这一点。

Plugin URL - https://wordpress.org/plugins/woocommerce/

插件网址 - https://wordpress.org/plugins/woocommerce/

2 个解决方案

#1


0  

You can use hooks/actions/filters to do so. Here is documentation on doing something like you want http://docs.woothemes.com/document/add-a-custom-field-in-an-order-to-the-emails/

您可以使用钩子/动作/过滤器来执行此操作。以下是关于做你想要的事情的文档http://docs.woothemes.com/document/add-a-custom-field-in-an-order-to-the-emails/

/**
 * Add the field to order emails
 **/
add_filter('woocommerce_email_order_meta_keys', 'my_woocommerce_email_order_meta_keys');

function my_woocommerce_email_order_meta_keys( $keys ) {
    $keys['How did you hear about us?'] = 'hear_about_us';
    return $keys;
}

#2


0  

To expand upon the above tutorial and now taking advantage of the improved email template hooks that I added and I think were released in WC 2.3.0

扩展上面的教程,现在利用我添加的改进的电子邮件模板钩子,我认为在WC 2.3.0中发布了

function so_229971110_add_meta_to_email( $order, $sent_to_admin, $plain_text ){
   $prodmetaa = get_post_meta($order->id, "Phone_number" , True);
   echo "Phone Number: " . $prodmetaa;
}
add_action( 'woocommerce_email_customer_details', 'so_229971110_add_meta_to_email', 20, 3 );

#1


0  

You can use hooks/actions/filters to do so. Here is documentation on doing something like you want http://docs.woothemes.com/document/add-a-custom-field-in-an-order-to-the-emails/

您可以使用钩子/动作/过滤器来执行此操作。以下是关于做你想要的事情的文档http://docs.woothemes.com/document/add-a-custom-field-in-an-order-to-the-emails/

/**
 * Add the field to order emails
 **/
add_filter('woocommerce_email_order_meta_keys', 'my_woocommerce_email_order_meta_keys');

function my_woocommerce_email_order_meta_keys( $keys ) {
    $keys['How did you hear about us?'] = 'hear_about_us';
    return $keys;
}

#2


0  

To expand upon the above tutorial and now taking advantage of the improved email template hooks that I added and I think were released in WC 2.3.0

扩展上面的教程,现在利用我添加的改进的电子邮件模板钩子,我认为在WC 2.3.0中发布了

function so_229971110_add_meta_to_email( $order, $sent_to_admin, $plain_text ){
   $prodmetaa = get_post_meta($order->id, "Phone_number" , True);
   echo "Phone Number: " . $prodmetaa;
}
add_action( 'woocommerce_email_customer_details', 'so_229971110_add_meta_to_email', 20, 3 );