WooCommerce某些产品的新订单电子邮件手动触发

问题描述:

我只需要了解特定产品中给定电子邮件地址的WooCommerce新订单电子邮件即可.

I need to know WooCommerce new order email to given email address for only in specific products.

例如:如果有人购买产品 X ,则需要向 Y 发送新订单电子邮件.未将 Y 设置为后端收件人.有实现这个目标的钩子吗?

Ex: if any body buy a product X need a new order email to Y. The Y is not set in as back end Recipient. Is there any hook to achieve this ?

我尝试关注

add_action( 'woocommerce_order_status_completed', 'custom_woocommerce_order_status_completed' );
function custom_woocommerce_order_status_completed( $order_id ) {
    $order = new WC_Order($order_id);

    $items = $order->get_items();

    foreach ($items as $key => $value) {
        if($value == 10) { // given product id
            // trigger order complete email for specific email address
        }
    }
}

您可以将以下内容放入您的functions.php中:

You can put the following in your functions.php:

add_filter( 'woocommerce_email_recipient_customer_completed_order', 'your_email_recipient_filter_function', 10, 2);

function your_email_recipient_filter_function($recipient, $object) {
    $recipient = $recipient . ', me@myemail.com';
    return $recipient;
}

唯一的缺点是收件人将同时看到您的地址和他自己在收件人:"字段中.

the only drawback is that the recipient will see both your address & his own in the To: field.

或者,您可以使用woocommerce_email_headers过滤器.传递的$ object允许您仅将其应用于已完成的订单电子邮件:

Alternatively, you can use the woocommerce_email_headers filter. the $object passed allows you to only apply this to the completed order email:

add_filter( 'woocommerce_email_headers', 'mycustom_headers_filter_function', 10, 2);

function mycustom_headers_filter_function( $headers, $object ) {
    if ($object == 'customer_completed_order') {
        $headers .= 'BCC: My name <my@email.com>' . "\r\n";
    }

    return $headers;
}

来自此答案来自 查看全文