我试图在订单确认电子邮件中显示一条特定的消息,如果您的订单中有一种产品处于落后状态。
我正在努力获得正确的功能,以扫描所有的产品,并使我的布尔工作。
我现在的代码是:
add_action( 'woocommerce_email_after_order_table', 'backordered_items_checkout_notice_email', 20, 4 );
function backordered_items_checkout_notice_email( $order, $sent_to_admin, $plain_text, $email ) {
$found2 = false;
foreach ( $order->get_items() as $item ) {
if( $item['data']->is_on_backorder( $item['quantity'] ) ) {
$found2 = true;
break;
}
}
if( $found2 ) {
if ( $email->id == 'customer_processing_order' ) {echo ' <strong>'.__('⌛ One or several products are Currently out of stock. <br/>Please allow 2-3 weeks for delivery.', 'plugin-mve').'</strong><br/>';}
}
}使用此代码,当您单击“订单”时,页面就会冻结,不会发送电子邮件。但我在后台拿到了订单。
有人能帮我修一下吗?
发布于 2021-12-14 13:42:54
您的代码包含一个关键的未理解错误,即:调用null上的成员函数is_on_backorder()
下面的代码将添加customer_processing_order电子邮件通知的消息。另见:How to target other WooCommerce order emails
所以你得到了:
function action_woocommerce_email_after_order_table( $order, $sent_to_admin, $plain_text, $email ) {
// Initialize
$flag = false;
// Target certain email notification
if ( $email->id == 'customer_processing_order' ) {
// Iterating through each item in the order
foreach ( $order->get_items() as $item ) {
// Get a an instance of product object related to the order item
$product = $item->get_product();
// Check if the product is on backorder
if ( $product->is_on_backorder() ) {
$flag = true;
// Stop the loop
break;
}
}
// True
if ( $flag ) {
echo '<p style="color: red; font-size: 30px;">' . __( 'My message', 'woocommerce' ) . '</p>';
}
}
}
add_action( 'woocommerce_email_after_order_table', 'action_woocommerce_email_after_order_table', 10, 4 );https://stackoverflow.com/questions/70349709
复制相似问题