取消Woocommerce订阅电子邮件(通过php而非管理控制台)

时间:2019-02-09 17:39:51

标签: woocommerce hook-woocommerce woocommerce-subscriptions

我正在尝试禁用许多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订阅挂钩上似乎很少有文档(至少我可以找到),所以我正在努力弄清楚我需要做些什么才能使它正常工作。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

没关系,我只需要睡个好觉就可以了!对于那些后来在细节上偶然发现这些问题的人,如下。

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

  • 新订单(发送给管理员)在class-wc-email-new-order.phpwoocommerce/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;
}