我在我的WooCommerce安装中创建了一个自定义订单状态,称为“报价”。
/*
* Change order status on new orders depending on order contents:
* If any product in the order is availble for quote, return 'quote' status.
* Otherwise the order status will be set to processing.
*/
add_filter ('woocommerce_payment_complete_order_status', 'change_status_to_quote_if_applicable', 10, 2);
function change_status_to_quote_if_applicable($order_status, $order_id) {
$order = new WC_Order($order_id);
$items = $order->get_items();
foreach ($items as $item) {
$product = get_product($item['product_id']);
if(product_available_for_quote($product)){
return 'quote';
}
}
return $order_status;
}
现在我想在收到状态为报价的订单时收到电子邮件。 我根据这篇有用的文章创建了一个插件:http://www.skyverge.com/blog/how-to-add-a-custom-woocommerce-email/
我的插件基本上是从文章中复制的,我只是更改了电子邮件的内容。 我想要更改的是触发电子邮件的方式。
文章中的插件如下:
// Trigger on new paid orders
add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $this, 'trigger' ) );
add_action( 'woocommerce_order_status_failed_to_processing_notification', array( $this, 'trigger' ) );
我希望在订单状态变为“报价”时触发电子邮件。 我已经这样做了:
// Trigger on new quote orders
add_action( 'woocommerce_order_status_pending_to_quote', array( $this, 'trigger' ) );
当订单达到“报价”状态时,没有任何反应。我已经检查了class-wc-order.php文件,特别是函数update_status
,因为这里触发了woocommerce_order_status_.$this->status._to_.$new_status->slug
。我使用了error_log函数来查看woocommerce_order_status_pending_to_quote
操作是否存在,确实存在。但是我的插件中的触发函数从未运行。
有什么想法吗?我尝试了很多不同的钩子,但似乎无法使触发函数运行。
非常感谢!