【发布时间】:2021-07-20 11:16:15
【问题描述】:
我正在尝试根据运费和订单备注是否为空,将信息添加到客户完整的订单电子邮件中。
根据订单备注字段是否填写,两条不同的消息。我已经下了测试订单,但没有任何显示。
这是我要开始工作的代码:
add_action( 'woocommerce_email_order_details', 'local_pickup_order_instructions', 10, 4 );
function local_pickup_order_instructions( $order, $sent_to_admin, $plain_text, $email ) {
if ( 'customer_completed_order' != $email->id ) return;
foreach( $order->get_items('shipping') as $shipping_item ) {
$shipping_rate_id = $shipping_item->get_method_id();
$method_array = explode(':', $shipping_rate_id );
$shipping_method_id = reset($method_array);
if ('local_pickup' == $shipping_method_id && empty($_POST['order_comments'])){ ?>
<div style="">Your instructions text here</div>
<?php
break;
}
else {
if ('local_pickup' == $shipping_method_id && !empty($_POST['order_comments'] ) ) { ?>
<div style="">Your instructions text here</div>
<?php
}
}
}
}
【问题讨论】:
标签: php wordpress woocommerce email-notifications shipping-method