首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我正在使用一个脚本,不发送零续订电子邮件它适用于客户电子邮件,但不适用于管理员电子邮件

我正在使用一个脚本,不发送零续订电子邮件它适用于客户电子邮件,但不适用于管理员电子邮件
EN

Stack Overflow用户
提问于 2021-06-08 03:30:25
回答 1查看 36关注 0票数 1

我正在使用一个脚本的woocommerce,不发送续订电子邮件的零续期,但它是工作的客户电子邮件,我想相同的管理员可以谁可以帮助我Here is the link to script i am using

EN

回答 1

Stack Overflow用户

发布于 2021-06-08 03:59:44

这些是WooCommerce订阅中使用的以下电子邮件类。

代码语言:javascript
运行
复制
$email_classes['WCS_Email_New_Renewal_Order']              = new WCS_Email_New_Renewal_Order();
$email_classes['WCS_Email_New_Switch_Order']               = new WCS_Email_New_Switch_Order();
$email_classes['WCS_Email_Processing_Renewal_Order']       = new WCS_Email_Processing_Renewal_Order();
$email_classes['WCS_Email_Completed_Renewal_Order']        = new WCS_Email_Completed_Renewal_Order();
$email_classes['WCS_Email_Customer_On_Hold_Renewal_Order'] = new WCS_Email_Customer_On_Hold_Renewal_Order();
$email_classes['WCS_Email_Completed_Switch_Order']         = new WCS_Email_Completed_Switch_Order();
$email_classes['WCS_Email_Customer_Renewal_Invoice']       = new WCS_Email_Customer_Renewal_Invoice();
$email_classes['WCS_Email_Cancelled_Subscription']         = new WCS_Email_Cancelled_Subscription();
$email_classes['WCS_Email_Expired_Subscription']           = new WCS_Email_Expired_Subscription();
$email_classes['WCS_Email_On_Hold_Subscription']           = new WCS_Email_On_Hold_Subscription();

WCS_Email_New_Switch_OrderWCS_Email_New_Switch_Order这是唯一向管理员发送电子邮件的类。

下面是在WCS_Email_New_Switch_OrderWCS_Email_New_Switch_Order中用来发送电子邮件的操作。

代码语言:javascript
运行
复制
'woocommerce_order_status_pending_to_processing_renewal_notification'
'woocommerce_order_status_pending_to_completed_renewal_notification'
'woocommerce_order_status_pending_to_on-hold_renewal_notification'
'woocommerce_order_status_failed_to_processing_renewal_notification'
'woocommerce_order_status_failed_to_completed_renewal_notification'
'woocommerce_order_status_failed_to_on-hold_renewal_notification'
'woocommerce_order_status_cancelled_to_processing_renewal_notification'
'woocommerce_order_status_cancelled_to_completed_renewal_notification'
'woocommerce_order_status_cancelled_to_on-hold_renewal_notification'
'woocommerce_subscriptions_switch_completed_switch_notification'

因此,您还必须使用回调函数eg_maybe_remove_email添加上述操作。检查下面的代码。

代码语言:javascript
运行
复制
<?php
/*
Plugin Name: WooCommerce Subscriptions No $0 Emails
Plugin URI:
Description: Do not send a processing or completed renewal order emails to customers when the order or renewal is for $0.00.
Author:
Author URI:
Version: 0.1
*/

function eg_maybe_remove_email( $order_id ){

    $order = new WC_Order( $order_id );

    if ( 0 == $order->get_total() ) {

        $email_class = array();
        
        switch( current_filter() ) {
            case 'woocommerce_order_status_completed_renewal_notification':
                $email_class[] = 'WCS_Email_Completed_Renewal_Order';
                break;
            case 'woocommerce_order_status_pending_to_processing_renewal_notification':
                $email_class[] = 'WCS_Email_Processing_Renewal_Order';
                $email_class[] = 'WCS_Email_New_Renewal_Order';
                break;
            case 'woocommerce_order_status_failed_renewal_notification':
                $email_class[] = 'WCS_Email_Customer_Renewal_Invoice';
                $email_class[] = 'WCS_Email_New_Renewal_Order';
                break;
            case 'woocommerce_order_status_pending_to_completed_renewal_notification':
            case 'woocommerce_order_status_pending_to_on-hold_renewal_notification':
            case 'woocommerce_order_status_failed_to_processing_renewal_notification':
            case 'woocommerce_order_status_failed_to_completed_renewal_notification':
            case 'woocommerce_order_status_failed_to_on-hold_renewal_notification':
            case 'woocommerce_order_status_cancelled_to_processing_renewal_notification':
            case 'woocommerce_order_status_cancelled_to_completed_renewal_notification':
            case 'woocommerce_order_status_cancelled_to_on-hold_renewal_notification':
                $email_class[] = 'WCS_Email_New_Renewal_Order';
                break;
            case 'woocommerce_subscriptions_switch_completed_switch_notification':
                $email_class[] = 'WCS_Email_New_Switch_Order';
                break;
            default:
                $email_class[] = array();
                break;
        }

        if ( ! empty( $email_class ) ) {
            foreach ( $email_class  as $key => $email ) {
                remove_action( current_filter(), array( WC()->mailer()->emails[ $email ], 'trigger' ) );
            }
        }

    }
    
}

//customer
add_action( 'woocommerce_order_status_completed_renewal_notification',             'eg_maybe_remove_email', 0, 1 );
add_action( 'woocommerce_order_status_pending_to_processing_renewal_notification', 'eg_maybe_remove_email', 0, 1 );
add_action( 'woocommerce_order_status_failed_renewal_notification',                'eg_maybe_remove_email', 0, 1 );

//admin
add_action( 'woocommerce_order_status_pending_to_completed_renewal_notification',    'eg_maybe_remove_email', 0, 1  );
add_action( 'woocommerce_order_status_pending_to_on-hold_renewal_notification',      'eg_maybe_remove_email', 0, 1  );
add_action( 'woocommerce_order_status_failed_to_processing_renewal_notification',    'eg_maybe_remove_email', 0, 1  );
add_action( 'woocommerce_order_status_failed_to_completed_renewal_notification',     'eg_maybe_remove_email', 0, 1  );
add_action( 'woocommerce_order_status_failed_to_on-hold_renewal_notification',       'eg_maybe_remove_email', 0, 1  );
add_action( 'woocommerce_order_status_cancelled_to_processing_renewal_notification', 'eg_maybe_remove_email', 0, 1  );
add_action( 'woocommerce_order_status_cancelled_to_completed_renewal_notification',  'eg_maybe_remove_email', 0, 1  );
add_action( 'woocommerce_order_status_cancelled_to_on-hold_renewal_notification',    'eg_maybe_remove_email', 0, 1  );
add_action( 'woocommerce_subscriptions_switch_completed_switch_notification',        'eg_maybe_remove_email', 0, 1  );
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67877663

复制
相关文章

相似问题

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