从 Woocommerce 设置电子邮件列表中删除未使用的电子邮件 [英] Remove unused emails from Woocommerce settings emails list

查看:48
本文介绍了从 Woocommerce 设置电子邮件列表中删除未使用的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天前,我问我如何在 WooCommerce 中重命名自定义电子邮件模板.现在我的问题是我有一些不需要的电子邮件模板,我想完全隐藏这些模板.我怎样才能做到这一点?我在 SO 和 Google 上搜索过,但找不到教程.

A few days ago I've asked how I can rename custom email templates in WooCommerce. Now I have the problem that I have some email templates which I don't need and I want to hide these templates completely. How can I do this? I've searched on SO and Google but can't find a tutorial.

推荐答案

更新: 正确的解决方案是使用 woocommerce_email_classes 过滤器钩子位于 WC_Emails 类:

Update: The right solution is using woocommerce_email_classes filter hook locate in WC_Emails Class:

add_filter( 'woocommerce_email_classes', 'remove_specific_email_classes', 10, 1 );
function remove_specific_email_classes( $emails ) {
    unset($emails['WC_Email_New_Order']);
    unset($emails['WC_Email_Cancelled_Order']);
    unset($emails['WC_Email_Failed_Order']);
    unset($emails['WC_Email_Customer_On_Hold_Order']);
    unset($emails['WC_Email_Customer_Processing_Order']);
    unset($emails['WC_Email_Customer_Completed_Order']);
    unset($emails['WC_Email_Customer_Refunded_Order']);
    unset($emails['WC_Email_Customer_Invoice']);
    unset($emails['WC_Email_Customer_Note']);
    unset($emails['WC_Email_Customer_Reset_Password']);
    unset($emails['WC_Email_Customer_New_Account']);

    return $emails;
}

代码位于您的活动子主题(活动主题)的 function.php 文件中.经测试有效.

Code goes in function.php file of your active child theme (active theme). Tested and works.

以下 官方 Woocommerce 记录 挂钩函数将删除通知操作挂钩:

The following official Woocommerce documented hooked function will remove notifications action hooks:

add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );
function unhook_those_pesky_emails( $email_class ) {

    //Hooks for sending emails during store events
    remove_action( 'woocommerce_low_stock_notification', array( $email_class, 'low_stock' ) );
    remove_action( 'woocommerce_no_stock_notification', array( $email_class, 'no_stock' ) );
    remove_action( 'woocommerce_product_on_backorder_notification', array( $email_class, 'backorder' ) );

    // New order emails
    remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
    remove_action( 'woocommerce_order_status_pending_to_completed_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
    remove_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
    remove_action( 'woocommerce_order_status_failed_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
    remove_action( 'woocommerce_order_status_failed_to_completed_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
    remove_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );

    // Processing order emails
    remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
    remove_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );

    // Completed order emails
    remove_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) );

    // Note emails
    remove_action( 'woocommerce_new_customer_note_notification', array( $email_class->emails['WC_Email_Customer_Note'], 'trigger' ) );
}

代码位于您的活动子主题(活动主题)的 function.php 文件中.经测试有效.

Code goes in function.php file of your active child theme (active theme). Tested and works.

这篇关于从 Woocommerce 设置电子邮件列表中删除未使用的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆