在电子邮件通知中显示自定义订单元数据值WooCommerce [英] Display custom order meta data value in email notifications WooCommerce

查看:75
本文介绍了在电子邮件通知中显示自定义订单元数据值WooCommerce的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于以下代码

在WooCommerce结帐中添加自定义复选框,该值以管理员编辑顺序显示

我试图添加 my_field_name 来订购确认电子邮件.据我了解,我必须使用 woocommerce_email_customer_details .

I tried to add my_field_name to order confirmation email. As I understand I have to use woocommerce_email_customer_details.

不幸的是,我来到了这个解决方案,没有得到想要的结果.

So I came to this solution, unfortunately without the desired result.

add_action('woocommerce_email_customer_details','woocommerce_email_order_invoice_number', 28, 4 );
function woocommerce_email_order_invoice_number( $order, $sent_to_admin, $plain_text, $email ) {
  if( $my_field_name = get_post_meta( $order->get_id(), 'my_field_name', true ) ) 
      echo '<p><strong>My custom field: </strong> <span style="color:red;">Is enabled</span></p>';
}

推荐答案

通过if条件" $ email-> id == ..." 您可以定位邮件

You have some minor mistakes, via the if condition "$email->id == ..." you can target the mails

如何定位其他WooCommerce订单电子邮件

  • 'customer_completed_order'
  • 'customer_processing_order'
  • 'customer_on_hold_order'
  • 'customer_refunded_order'
  • 'customer_reset_password'
  • 'customer_invoice'
  • 'customer_new_account'
  • 'customer_note'
  • 取消订单"
  • 失败订单"
  • 新订单"


function woocommerce_email_order_invoice_number( $order, $sent_to_admin, $plain_text, $email ) {
    // For 'new order'
    if ( $email->id == 'new_order' ) {
    
        // Get post meta
        $my_field_name = get_post_meta( $order->get_id(), 'my_field_name', true );
   
        // True and equal to     
        if ( $my_field_name && $my_field_name == 1 ) {
            echo '<p><strong>My custom field: </strong> <span style="color:red;">Is enabled</span></p>';
        }
    }
}
add_action( 'woocommerce_email_customer_details', 'woocommerce_email_order_invoice_number', 20, 4 );

这篇关于在电子邮件通知中显示自定义订单元数据值WooCommerce的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆