Woocommerce根据产品自定义字段添加新的订单电子邮件(管理员)收件人

时间:2019-09-26 05:51:35

标签: wordpress woocommerce

我有一个woocommerce站点的dropshippers,一个dropshipper(Dropshipper1)拥有大多数产品,但我们从其他供应商那里订购了一些专门的产品。目前,Dropshipper1使用插件(Articnet的Woocommerce Dropshippers)获得了产品订单以及装箱单。然后,他将订单发货并通知我们。效果很好。

当购物车包含Dropshipper1的产品和我们从Dropshipper1提货后自行运送的特殊产品时,就会出现问题。然后,我们需要在捆绑产品之前确保他没有运送订单的一部分,以便我们希望他获得完整的订单详细信息。

仅当购物车包含特殊产品及其产品时,我才需要向Dropshipper1管理员发送新订单电子邮件。当订单仅包含特殊产品时,我不希望他收到管理员的新订单电子邮件。

我尝试了woocommerce通知和此处发布的代码的变体,但是什么也没有发生……我想我缺少一个关键要素,但我不知道它是什么。我已将以下代码放入子主题函数文件中。

add_filter( 'woocommerce_email_recipient_new_order', 'new_order_conditional_email_recipient', 10, 2 );
function new_order_conditional_email_recipient( $recipient, $order ) {
    if ( ! is_a( $order, 'WC_Order' ) ) return $recipient; 

foreach( $order->get_items() as $item_id => $item ){ // Get the custom field value (with the right $order_id) $dropshipper =wc_get_order_item_meta( $item_id, 'woo_dropshipper', true ); if ($dropshipper == "Corinne") $recipient .= ', va365team@gmail.com'; } return $recipient;

}

我没有收到任何错误消息,但是也没有电子邮件发送。我已经尝试了几种变种,但都没有成功。

非常感谢您的帮助或帮助。

0 个答案:

没有答案