【发布时间】:2016-08-30 13:10:27
【问题描述】:
我有一个用于管理我的货件的插件,它有两种自定义状态:等待发货和已发货。
我尝试添加在订单传递到发货时发送的电子邮件。
我在 Stack Overflow 上找到了这个:Woocommerce Refund Email 但我可以弄清楚它是如何工作的
这是我的插件文件代码:
我根据 helgatheviking 和 Adrien Leber 的建议更新了我的代码
function shippement_tracking_filter_actions( $actions ){
$actions[] = "woocommerce_order_status_shipped";
return $actions;
}
add_filter( 'woocommerce_email_actions', 'shippement_tracking_filter_actions' );
function add_expedited_order_woocommerce_email( $email_classes ) {
require( 'includes/class-wc-expedited-order-email.php' );
$email_classes['WC_Expedited_Order_Email'] = new WC_Expedited_Order_Email();
return $email_classes;
}
add_filter( 'woocommerce_email_classes', 'add_expedited_order_woocommerce_email' );`
还有我的班级:
class WC_Expedited_Order_Email extends WC_Email {
public function __construct() {
$this->id = 'expedited_order_tracking';
$this->customer_email = true;
$this->title = __( 'Shippement Traking', 'customEmail' );
$this->description = __( 'Sent tracking email to customer', 'customEmail' );
$this->heading = __( 'Your {site_title} order is shipped', 'customEmail' );
$this->subject = __( 'Your {site_title} order from {order_date} is shipped', 'customEmail' );
$this->template_html = 'emails/customer-order_tracking.php';
$this->template_plain = 'emails/plain/customer-order_tracking.php';
add_action( 'woocommerce_order_status_shipped', array( $this, 'trigger' ) );
parent::__construct();
}
public function trigger( $order_id )
{
var_dump($order_id);die();
}
当我更改订单状态时,什么也没有发生!我的触发函数从不调用。
谁能帮帮我?
【问题讨论】:
-
我可能会使用
$email_actions[] = 'woocommerce_order_status_shipped;而不是过渡。虽然我认为真正的交易杀手是你没有在这里传递类的新实例$email_classes['WC_Expedited_Order_Email']你正在传递包含的文件。在上面的行中包含该文件,然后实例化该类。见this tutorial -
感谢您的回答@helgatheviking。我试过了,但我认为我的触发函数仍然没有被调用
-
也许 $order_id 没有通过?如果你在
die()之前echo "something"怎么办? -
是的,我试过了,但我没有看到我的回声,我认为我的触发函数永远不会调用,但我不明白为什么
-
经过一番研究!我觉得问题出在我在 add_action 中使用的状态:他是由外部模块添加的,而不是 WooCommerce 的核心!关于这个的想法?
标签: wordpress woocommerce