簡體   English   中英

在 Woocommerce 3.3 中下訂單后向客戶發送暫停訂單通知

[英]Send customer on-hold order notification once order is placed in Woocommerce 3.3

我有這個問題。 我現在在我的網站上使用 Woocommerce 3.3.3 並注意到一個奇怪的問題。 客戶下訂單后,他們的訂單被卡在“暫停”狀態到 Woocommerce 訂單中。

保持狀態

並且客戶沒有收到任何訂單確認郵件。 當轉到訂單並將訂單狀態從“暫停”移動到“處理中”時,客戶收到訂單確認郵件,這應該是自動的。 搜索,發現這個“修復”:

add_filter( ‘woocommerce_defer_transactional_emails’, ‘__return_false’ );

被放入functions.php,但似乎沒有改變什么。 有人有類似問題嗎?

請嘗試以下操作:

add_action('woocommerce_new_order', 'new_order_on_hold_notification', 30, 1 );
function new_order_on_hold_notification( $order_id ) {
    $order = wc_get_order( $order_id );

    // Only for on hold new orders
    if( ! $order->has_status('on-hold') )
        return; // Exit

    // Send Customer On-Hold Order notification
    WC()->mailer()->get_emails()['WC_Email_Customer_On_Hold_Order']->trigger( $order_id );
}

要將“暫停”已付款訂單更改為“正在處理”,請使用:

add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_prrocessing_paid_order', 10, 1 );
function custom_woocommerce_auto_prrocessing_paid_order( $order_id ) {
    if ( ! $order_id )
       return;

    $order = wc_get_order( $order_id );

    // No updated status for orders delivered with Bank wire, Cash on delivery and Cheque payment methods.
    if ( in_array( $order->get_payment_method(), array( 'bacs', 'cod', 'cheque', '' ) ) ) {
        return;
    } 
    // "Processing" updated status for paid Orders with all others payment methods
    else {
        if( $order->has_status('on-hold') )
            $order->update_status( 'processing' );
    }
}

代碼位於活動子主題(或活動主題)的 function.php 文件中。 它應該工作。

只是要指出:

@LoicTheAztec 提到的解決方案有效:

add_action('woocommerce_new_order', 'new_order_on_hold_notification', 30, 1 );
function new_order_on_hold_notification( $order_id ) {
    $order = wc_get_order( $order_id );

    // Only for on hold new orders
    if( ! $order->has_status('on-hold') )
        return; // Exit

    // Send Customer On-Hold Order notification
    WC()->mailer()->get_emails()['WC_Email_Customer_On_Hold_Order']->trigger( $order_id );
}

但是,此解決方案存在一個問題,在調用woocommerce_new_order掛鈎時,訂單尚未完全創建,因此在電子郵件通知中未顯示訂單項目。 請改用以下鈎子:

    add_action('woocommerce_checkout_order_processed', 'new_order_on_hold_notification');   
    function new_order_on_hold_notification( $order_id ) {
                    $order = wc_get_order( $order_id );

                    // Only for on hold new orders
                    if( ! $order->has_status('on-hold') )
                        return; // Exit

                    // Send Customer On-Hold Order notification
                    WC()->mailer()->get_emails()['WC_Email_Customer_On_Hold_Order']->trigger( $order_id );
     }

woocommerce_checkout_order_processed被調用時,訂單項目已經可用於您的電子郵件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM