【问题标题】:How to get the Woocommerce Current email id (like admin_new_order, customer_processing_order) inside the email template file [duplicate]如何在电子邮件模板文件中获取 Woocommerce 当前电子邮件 ID(如 admin_new_order、customer_processing_order)[重复]
【发布时间】:2018-11-19 06:45:31
【问题描述】:

我正在根据自己的需要定制 woocommerce 电子邮件模板。我只是想知道我是否可以访问当前的电子邮件 ID(例如 customer_processing_order 或 admin_new_order),以便可以在条件语句中使用它,例如

$email_id = /* Some function to get the email id */

if($email_id == 'admin_new_order') {
//do somthing

}

我想在 email-order-details.php 和 email-order-items.php 中使用它

谢谢

【问题讨论】:

  • 回声'
    '; print_r($email->id);回声'
    ';或者您可以在 email-order-details.php 文件中打印 $order 和 $email ......
  • 谢谢,解决了我的问题

标签: wordpress woocommerce email


【解决方案1】:

Techno Deviser 的评论是正确的。

email-order-details.php 中,您有一些可用的参数:

$order, $sent_to_admin, $plain_text, $email

$email 是一个包含订单信息等等的对象。 我看到id 始终可用。

所以你可以这样做:

$email_id = $email->id;

if($email_id == 'customer_note') {
  // another id i've seen during testing (just now) is: customer_on_hold_order

  //do somthing
}

注意:在 email-order-items.php 内部,$email 参数不可用。目前我不确定如何在此模板中获取某种电子邮件 ID,我将不得不进行更多调查。

问候,比约恩

【讨论】:

  • 非常感谢,我在主模板中尝试过,这就是它不起作用的原因。再次感谢。
  • 有没有办法在这个文件/templates/emails/email-order-items.php中得到这个
  • 通过解决方法,您可以首先使用钩子 woocommerce_email_order_details 获取 ID,然后使用自定义或 woocommerce_order_item_meta_start 钩子进行处理。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-07
相关资源
最近更新 更多