首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >禁用具有自定义属性的订单的Woocommerce订单通知

禁用具有自定义属性的订单的Woocommerce订单通知
EN

Stack Overflow用户
提问于 2021-09-20 17:14:55
回答 1查看 45关注 0票数 0

日安!我希望禁用Woocommerce的新订单通知,从其他平台同步的订单,因为他们已经自动标记为完成。目前,我正在收到来自所有导入订单的新订单通知。这些订单有自己的自定义字段。

是否可以使用钩子来编写自定义代码,以防止向管理员发送带有ced_shopee_order_shop_id或ced_lazada_seller_id属性的订单的新订单通知电子邮件?

我仍然希望在我的网站上收到订单的电子邮件通知。

任何帮助都将不胜感激!

目前,我已经修改了Víctor Calderón给出的代码,但它不适用于我的情况。

代码语言:javascript
运行
复制
add_filter('woocommerce_email_recipient_new_order', 'disable_notification_based_on_id', 10, 2);

function disable_notification_based_on_id($recipient, $order) {

    $page = $_GET['page'] = isset($_GET['page']) ? $_GET['page'] : '';
    if ('wc-settings' === $page) {
        return $recipient;
    }

    if (!$order instanceof WC_Order) {
        return $recipient;
    }
    $items = $order -> get_items();
    foreach($items as $item) {
        $shopee_id = $item['ced_shopee_order_shop_id'];
        $lazada_id = $item['ced_lazada_seller_id'];
        if ($shopee_id == 377700604 || $lazada_id == 1143399005) {
            $recipient = '';
        }
        return $recipient;
    }
}
EN

Stack Overflow用户

发布于 2021-09-21 12:30:14

我使用了以下代码来禁用基于产品id的通知(在我的示例中是产品id 5274),因此您应该尝试使用与您的值匹配的ced_shopee_order_shop_id或ced_lazada_seller_id来更改$item' product _id‘

代码语言:javascript
运行
复制
add_filter('woocommerce_email_recipient_new_order', 'disable_notification_based_on_id', 10, 2);
function disable_notification_based_on_id($recipient, $order)
{
    
    $page = $_GET['page'] = isset($_GET['page']) ? $_GET['page'] : '';
    if ('wc-settings' === $page) {
        return $recipient;
    }

    if (!$order instanceof WC_Order) {
        return $recipient;
    }
    //this is the example for product id==5274, change the value to your atribute
    $items = $order->get_items();
    foreach ($items as $item) {
        $product_id = $item['product_id'];// change to your atribute ced_shopee_order_shop_id OR ced_lazada_seller_id
        if ($product_id == 5274) {
            $recipient = '';
        }//change if condition to match your ced_shopee_order_shop_id OR ced_lazada_seller_id value
        return $recipient;
    }
}
票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69258442

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档