WooCommerce挂钩在电子邮件类的退款中触发电子邮件

时间:2014-08-17 21:24:44

标签: email woocommerce

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

我的问题是:我无法在扩展的电子邮件类中找到一个钩子来执行此操作。

我按照本教程编写了一个扩展WC_Email的类,并使所有工作除了之外我需要一个钩子来在订单状态被更改并保存为&#时触发该类34;退还":

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的自定义操作,但问题出在这里我不知道如何用这个来触发我的课程。它似乎在课前加载所以没有&#39 ;或者工作。)

只有在订单状态更改为“退款”时,才能通过扩展课程触发电子邮件发送?

1 个答案:

答案 0 :(得分: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' ) );