如果您訂單的幾種產品之一處于缺貨狀態,我會嘗試在訂單確認電子郵件中顯示一條特定訊息。
我正在努力獲得正確的功能來掃描所有產品并使我的布林值作業。
我目前的代碼:
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/>';}
}
}
使用此代碼,當您單擊“訂購”時,頁面會凍結并且不會發送電子郵件。但是我在后端得到了訂單。
誰能幫我解決一下?
uj5u.com熱心網友回復:
您的代碼包含一個 CRITICAL 未捕獲的錯誤,即:Call to a member function is_on_backorder() on null
以下代碼將為customer_processing_order電子郵件通知添加訊息。另請參閱:如何定位其他 WooCommerce 訂單電子郵件
所以你得到:
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://www.uj5u.com/ruanti/381050.html
標籤:WordPress的 求购 产品 命令 电子邮件通知
