php - 将运输方式和时间段添加到 woocommerce 电子邮件
问题描述
我想将所选的运输方式添加到我的 woocommerce“新订单”电子邮件的顶部。
我还想在此旁边添加选定的时间段(自定义字段:jckwds_timeslot)。
我知道我需要将 PHP 代码添加到 functions.php 文件中,但我不确定如何。
这是我已经用来在电子邮件顶部添加订购时间的代码:
add_action( 'woocommerce_email_order_details', 'custom_processing_order_notification', 1, 4 );
function custom_processing_order_notification( $order, $sent_to_admin, $plain_text, $email ) {
// Only for processing email notifications to customer
if( ! 'customer_processing_order' == $email->id ) return;
$date_modified = $order->get_date_modified();
$date_paid = $order->get_date_paid();
$date = empty( $date_paid ) ? $date_modified : $date_paid;
echo sprintf( '<p>Order NO. %s (placed at <time>%s</time>)</p>',
$order->get_order_number( ),
$date->date("g:i A")
);
}
解决方案
您可以使用$order->get_shipping_method()
检索订单的运输方式。您可以使用它$order->get_meta()
来检索自定义字段值。
add_action( 'woocommerce_email_order_details', 'custom_processing_order_notification', 1, 4 );
function custom_processing_order_notification( $order, $sent_to_admin, $plain_text, $email ) {
// Only for processing email notifications to customer
if( ! 'customer_processing_order' == $email->id ) return;
//Date
$date = empty( $date_paid ) ? $order->get_date_modified() : $order->get_date_paid();
printf( '<p>Order NO. %s (placed at <time>%s</time>)</p>', $order->get_order_number(), $date->date("g:i A") );
//Shipping method
printf( '<p>Shipping method: %s</p>', $order->get_shipping_method() );
//Time slot
printf( '<p>Time slot: %s</p>', $order->get_meta( 'jckwds_timeslot', true ) );
}
推荐阅读
- google-sheets - 计算谷歌表格中由“-”分隔的单元格范围内的单词数
- c# - 如何在 Parallel.ForEach 中应用异步
- python - office365 sharepoint open binary 给出缺少架构错误
- javascript - 为什么digest 和digest('hex') 会导致不同的输出?
- javascript - 移至下一步或返回步进材料 UI 时,数据未存储
- c# - 此错误的新内容:传递到字典中的模型项的类型为“System.Collections.Generic.List`1[]
- r - 开关错误(类(数组数据),矩阵 = {:EXPR 必须是长度为 1 的向量
- git - 在通过 HTTPS 为 Google Source Repository 调用 git clone 时,有没有办法传递访问令牌
- java - Apache Netbeans 输出窗口显示的不仅仅是结果
- python - 使用正则表达式仅提取艺术家姓名