programing

Woocommerce에서 취소된 주문으로 고객에게 이메일 보내기

showcode 2023. 3. 21. 22:44
반응형

Woocommerce에서 취소된 주문으로 고객에게 이메일 보내기

주문이 취소되면 고객에게 메일을 보내려고 합니다.기본적으로 woocommerce는 이 이메일을 사이트 관리자에게만 보냅니다.이 코드에 의해, Web상의 관련의 투고에 관한 문제가 해결되었습니다.

function wc_cancelled_order_add_customer_email( $recipient, $order ){
   return $recipient . ',' . $order->billing_email;
}
add_filter( 'woocommerce_email_recipient_cancelled_order', 'wc_cancelled_order_add_customer_email', 10, 2 );
add_filter( 'woocommerce_email_recipient_failed_order', 'wc_cancelled_order_add_customer_email', 10, 2 );

그러나 Woocommerce는 이러한 필터 후크를 완전히 제거한 것 같습니다.이 일을 할 수 있는 방법이 있을까요?

잘 부탁드립니다!

액션 훅에 연결된 이 커스텀 기능에서는 고객에게 대응하는 이메일 알림을 보내는 "취소" 및 "실패" 주문을 대상으로 합니다(관리자는 WooCommerce 자동 알림을 통해 해당 알림을 수신합니다).

add_action('woocommerce_order_status_changed', 'send_custom_email_notifications', 10, 4 );
function send_custom_email_notifications( $order_id, $old_status, $new_status, $order ){
    if ( $new_status == 'cancelled' || $new_status == 'failed' ){
        $wc_emails = WC()->mailer()->get_emails(); // Get all WC_emails objects instances
        $customer_email = $order->get_billing_email(); // The customer email
    }

    if ( $new_status == 'cancelled' ) {
        // change the recipient of this instance
        $wc_emails['WC_Email_Cancelled_Order']->recipient = $customer_email;
        // Sending the email from this instance
        $wc_emails['WC_Email_Cancelled_Order']->trigger( $order_id );
    } 
    elseif ( $new_status == 'failed' ) {
        // change the recipient of this instance
        $wc_emails['WC_Email_Failed_Order']->recipient = $customer_email;
        // Sending the email from this instance
        $wc_emails['WC_Email_Failed_Order']->trigger( $order_id );
    } 
}

코드가 기능합니다.php 파일 또는 임의의 플러그인 파일에 있는 활성 자식 테마(또는 테마)입니다.

이것은 WooCommerce 3+에서 동작합니다.

필요한 경우 이메일을 변경하는 대신 기존 수신인에 추가할 수 있습니다.

// Add a recipient in this instance
$wc_emails['WC_Email_Failed_Order']->recipient .= ',' . $customer_email;

관련 답변: 주문 상태가 보류에서 취소로 변경되면 이메일 알림 보내기

언급URL : https://stackoverflow.com/questions/47648386/sending-email-to-customer-on-cancelled-order-in-woocommerce

반응형