【问题标题】:Unhooking Woocommerce Subscriptions emails (via php not the admin dashboard)取消挂钩 Woocommerce 订阅电子邮件(通过 php 而不是管理仪表板)
【发布时间】:2019-02-09 17:39:50
【问题描述】:

我正在尝试禁用一些 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 hook-woocommerce woocommerce-subscriptions


    【解决方案1】:

    没关系找到它 - 我需要的只是睡个好觉!对于那些后来偶然发现的人,详细信息如下。

    您需要使用'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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-31
      • 2020-08-17
      • 2021-04-24
      • 1970-01-01
      • 1970-01-01
      • 2017-09-17
      • 2018-10-18
      相关资源
      最近更新 更多