【问题标题】:WooCommerce Hook to Trigger Email in Refund inside Email ClassWooCommerce 挂钩以在电子邮件类内的退款中触发电子邮件
【发布时间】:2014-08-17 21:24:44
【问题描述】:

默认情况下,WooCommerce 不会发送退款电子邮件,因为正如 Mike Jolley 所说,退款是“手动过程”。但是,我需要发送一个!

我的问题是:我找不到会在我的扩展电子邮件类中触发的钩子来执行此操作。

我按照本教程编写了一个类来扩展 WC_Email 并让一切正常除了我需要一个挂钩来在订单状态更改并保存为“已退款”时触发该类:

http://www.skyverge.com/blog/how-to-add-a-custom-woocommerce-email/

我尝试了各种钩子,例如 woocommerce_order_status_refund 代替第 39-40 行的 woocommerce_order_status_pending_to_processing_notification 钩子。

问题是woocommerce_order_status_refund 不会在电子邮件类中触发。它在其他地方也能正常工作,但在这种情况下却不行。

我尝试将钩子替换为woocommerce_order_actions_end 作为一种“通用”。我添加了一个 if (! $order->status == 'refunded') 来过滤“退款”。但是现在每次加载状态为“已退款”的订单时都会触发该钩子。

(我还尝试将带有 woocommerce_order_actions 的自定义操作添加到操作菜单中,但问题是在这里我不知道如何用它来触发我的课程。它似乎在课程之前加载,所以这也不起作用.)

只有当订单状态更改为“已退款”时,有没有办法通过扩展类触发电子邮件发送?

【问题讨论】:

    标签: email woocommerce


    【解决方案1】:

    引用此question,您必须做两件事才能获得退款状态以触发电子邮件。

    首先,您必须将woocommerce_order_status_refunded 钩子注册为将触发电子邮件的钩子。默认情况下不会。

    /**
     * Register the "woocommerce_order_status_refunded" hook which is necessary to
     * allow automatic email notifications when the order is changed to refunded.
     * 
     * @modified from https://stackoverflow.com/a/26413223/2078474 to remove anonymous function
     */
    add_action( 'woocommerce_init', 'so_25353766_register_email' );
    function so_25353766_register_email(){
        add_action( 'woocommerce_order_status_refunded', array( WC(), 'send_transactional_email' ), 10, 10 );
    }
    

    为 WooCommerce 2.3 编辑

    合并我的拉取请求后,WooCommerce 的下一版本(2.3)应该支持过滤触发电子邮件的操作。所以你可以通过过滤器添加退款状态:

    add_filter( 'woocommerce_init', 'so_26483961_filter_email_actions' );
    function so_26483961_filter_email_actions( $emails ){
        $emails[] = 'woocommerce_order_status_refunded';
        return $emails;
    }
    

    然后在您的自定义电子邮件类的_construct 方法中,您可以使用它作为触发器:

    add_action( 'woocommerce_order_status_refunded', array( $this, 'trigger' ) );
    

    【讨论】:

      猜你喜欢
      • 2014-10-22
      • 1970-01-01
      • 2023-03-16
      • 2017-06-03
      • 1970-01-01
      • 1970-01-01
      • 2019-01-22
      • 2022-11-20
      • 1970-01-01
      相关资源
      最近更新 更多