解钩WooCommerce订阅电子邮件(通过php,而不是管理仪表板) [英] Unhooking Woocommerce Subscriptions emails (via php not the admin dashboard)

查看:13
本文介绍了解钩WooCommerce订阅电子邮件(通过php,而不是管理仪表板)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试禁用一些WC订阅电子邮件(这样它们就不会被发送)。我知道我可以在管理设置区域手动完成此操作,但我正尝试通过PHP(在插件中)完成此操作。这样做的原因是,当它从测试站点移动到活动站点时,可以简单地复制相关文件,并且不需要更改任何手动设置。

例如-删除发送给站点管理员的新续订订单。

add_action( 'woocommerce_email', 'SA_unhook_unneeded_emails' );
function SA_unhook_unneeded_emails( $email_class ) {
    //remove new_renewal_order email (sent to admin)
    remove_action( 'woocommerce_order_status_pending_to_processing_renewal_notification', array( $this, 'trigger' ) );
    remove_action( 'woocommerce_order_status_pending_to_completed_renewal_notification', array( $this, 'trigger' ) );
    remove_action( 'woocommerce_order_status_pending_to_on-hold_renewal_notification', array( $this, 'trigger' ) );
    remove_action( 'woocommerce_order_status_failed_to_processing_renewal_notification', array( $this, 'trigger' ) );
    remove_action( 'woocommerce_order_status_failed_to_completed_renewal_notification', array( $this, 'trigger' ) );
    remove_action( 'woocommerce_order_status_failed_to_on-hold_renewal_notification', array( $this, 'trigger' ) );
    //remove_action( 'woocommerce_order_status_completed_renewal_notification', array( $this, 'trigger' ) );

}

取消注释最后一个REMOVE_ACTION没有什么不同。这些电子邮件仍在发送。我已尝试将woocommerce_email更改为wp_head,以查看是否有任何变化,但没有任何变化。

关于WC订阅挂钩的文档似乎很少(至少我能找到),所以我很难弄清楚我到底需要做些什么才能让它正常工作。

如有任何帮助,我们将不胜感激。

推荐答案

没关系找到了--我所需要的就是睡个好觉!对于那些后来偶然发现这一点的人,详细信息如下所示。

您需要使用'woocommerce_email_enabled_'.this->id筛选器。ID(this->id)可以在该电子邮件类型的相关类文件中找到。例如

  • 新订单(发送给管理员)位于class-wc-email-new-order.php(woocommerce/includes文件夹)包含$this->id = 'new_order';
  • 新续订订单(已发送给管理员)new_renewal_order
  • 续订订单(发送给客户)为customer_processing_renewal_ordercustomer_completed_renewal_order
//stop emails without using the admin dashboard to manually set enabled/disabled status
add_filter( 'woocommerce_email_enabled_new_order', 'SA_stopemails', 10, 2); //new order sent to admin
add_filter( 'woocommerce_email_enabled_customer_on_hold_order', 'SA_stopemails', 10, 2); //order on hold sent to customer
add_filter( 'woocommerce_email_enabled_customer_processing_order', 'SA_stopemails', 10, 2); //order in processing sent to customer
add_filter( 'woocommerce_email_enabled_new_renewal_order', 'SA_stopemails', 10, 2); //new renewal order sent to admin
add_filter( 'woocommerce_email_enabled_customer_processing_renewal_order', 'SA_stopemails', 10, 2); //renewal order processing sent to customer
add_filter( 'woocommerce_email_enabled_customer_completed_renewal_order', 'SA_stopemails', 10, 2); //renewal order completed sent to customer

function SA_stopemails( $active, $order ) {
    return false;
}

这篇关于解钩WooCommerce订阅电子邮件(通过php,而不是管理仪表板)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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