首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >停止$0价值产品的WooCommerce订阅管理员续订通知

停止$0价值产品的WooCommerce订阅管理员续订通知
EN

Stack Overflow用户
提问于 2021-06-08 02:35:57
回答 1查看 63关注 0票数 0

我发现了以下插件,当续订价值为0美元的订阅时,它会停止向客户发送通知。这对客户来说工作得很好,但管理员仍然会收到通知。是否有可能修改代码,以消除发送续订电子邮件给管理员?

感谢您的帮助

代码语言:javascript
复制
<?php
/*
Plugin Name: WooCommerce Subscriptions No $0 Emails
Plugin URI:
Description: Do not send 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() ) {

        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';
                break;
            case 'woocommerce_order_status_failed_renewal_notification':
                $email_class = 'WCS_Email_Customer_Renewal_Invoice';
                break;
            default:
                $email_class = '';
                break;
        }

        if ( ! empty( $email_class ) ) {
            remove_action( current_filter(), array( WC()->mailer()->emails[ $email_class ], 'trigger' ) );
        }
    }
    
    if ( 0 == $order->get_total() ) {

        switch( current_filter() ) {
            case 'woocommerce_order_status_failed_renewal_notification':
                $email_class = 'WCS_Email_New_Renewal_Order';
                break;
            default:
                $email_class = '';
                break;
        }

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

}
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 );
EN

回答 1

Stack Overflow用户

发布于 2021-06-08 03:01:27

这些是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  );
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67877047

复制
相关文章

相似问题

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