Woocommerce-发送电子邮件给其他人

时间:2019-10-10 14:38:03

标签: woocommerce

我有一个自定义字段,其中包含另一个客户电子邮件帐户。

我的想法是,当订单的状态更改为WAIT,PENDING,PROCESSING或COMPLETED时,它将到达此字段中配置的电子邮件。

这可能吗?

没有问题,不需要编程,但是我不知道该使用哪个钩子。

谢谢。

3 个答案:

答案 0 :(得分:1)

这可能非常有用: https://www.skyverge.com/blog/add-woocommerce-email-recipients-conditionally/ 我将考虑“注意事项”部分。

答案 1 :(得分:1)

例如,您可以使用woocommerce_order_status_changed钩子在每次状态更改时通知某人,例如以下示例:

add_action('woocommerce_order_status_changed', 'send_custom_email_notifications', 10, 4 );
function send_custom_email_notifications( $order_id, $old_status, $new_status, $order ){          

    $to_email    = 'john.doe@gmail.com'; // <= Replace with your email custom field (the recipient)
    $shop_name   = __('Shop name'); // Set the shop name
    $admin_email = 'shop@email.com'; // Set default admin email

    $subject  = sprintf( __('Order %s has changed to "%s" status'), $order_id, $new_status ); // The subject
    $message  = sprintf( __('Order %s has changed to "%s" status'), $order_id, $new_status ); // Message content
    $headers  = sprintf( __('From: %s <%s>'), $shop_name, $admin_email ) . "\r\n"; // From admin email

    wp_mail( $to_email, $subject, $message, $headers ); // Send the email
}

代码进入活动子主题(或活动主题)的functions.php文件中。经过测试并可以正常工作

答案 2 :(得分:1)

在活动主题的functions.php中添加以下代码段-

function add_cc_to_wc_order_emails( $header, $mail_id, $mail_obj ) {
    $available_for = array( 'customer_on_hold_order', 'customer_processing_order', 'customer_completed_order' );
    if( in_array( $mail_id, $available_for ) ) {
        $cc_email = 'addyour@ccmail.com';
        $cc_username = "yourCCUser";
        $formatted_email = utf8_decode( $cc_username . ' <' . $cc_email . '>' );
        $header .= 'Cc: ' . $formatted_email . "\r\n";
    }
    return $header;
}
add_filter( 'woocommerce_email_headers', 'add_cc_to_wc_order_emails', 99, 3 );