从Woocommerce设置电子邮件列表中删除未使用的电子邮件

时间:2018-11-09 20:24:27

标签: php wordpress woocommerce email-notifications

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

enter image description here

2 个答案:

答案 0 :(得分:1)

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

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文件中。经过测试,可以正常工作。


以下official Woocommerce documented挂钩函数将删除通知操作挂钩:

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文件中。经过测试,可以正常工作。

答案 1 :(得分:0)

这是我的解决方案。我不确定有什么更好的吗?

add_filter( 'woocommerce_email_classes', 'remove_unused_emails', 15 );
function remove_unused_emails( $email_classes ) {

    //Unset unused email templates
    unset( $email_classes['WC_Email_Customer_Reset_Password'] );
    unset( $email_classes['WC_Email_Customer_New_Account'] );
    unset( $email_classes['WC_Email_Customer_On_Hold_Order'] );
    unset( $email_classes['WC_GZD_Email_Customer_New_Account_Activation'] );
    unset( $email_classes['WC_GZD_Email_Customer_Revocation'] );
    unset( $email_classes['WC_GZD_Email_Customer_Ekomi'] );
    unset( $email_classes['WC_GZD_Email_Customer_Trusted_Shops'] );

    return $email_classes;

}