WooCommerce订单状态挂钩未触发 [英] WooCommerce order status hook not triggering

查看:137
本文介绍了WooCommerce订单状态挂钩未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里使用此小功能来检测是否已将订单设置为待处理状态.这发生在付款页面和付款提供商通知之间:

I'm using this little function here to detect if an order is set into pending. This happens between the payment page and the payment provider notification:

add_action( 'woocommerce_order_status_pending', 'status_pending' );
function status_pending( $related_job ) {
    error_log('Triggered');
}

问题是我没有收到任何错误日志,该日志显示出该功能有效.但这变得更加疯狂.当我通过仪表板将状态从已完成更新为未决时,将显示日志.所以我绝对不知道为什么在结帐过程中它不起作用.有什么建议或想法可能是什么问题?

The problem is that I don't get any error log which shows me that the function work. But it becomes crazier. When I update the status via the dashboard from completed to pending, the log appears. So I've absolutely no idea why it's not working during the checkout process. Any recommendations or ideas what could be the problem?

推荐答案

待处理"订单状态是在创建订单后客户进入支付网关之前订单的默认状态.

The "pending" order status is the default status for orders before customer get on a payment gateway, just after order creation.

因此,最好的方法是在创建订单后,在付款方式处理之前使用挂钩:

So the best way is to use a hook once the order is created, before payment method process:

1)首先尝试woocommerce_checkout_order_processed动作钩子(3个参数):

1) try first the woocommerce_checkout_order_processed action hook (3 args):

add_action( 'woocommerce_checkout_order_processed', 'order_processed_with_pending_status', 10, 3 );
function order_processed_with_pending_status( $order_id, $posted_data, $order ) {
    error_log('Triggered');
}

2)或者尝试使用woocommerce_checkout_update_order_meta动作钩子(2 args):

2) Alternatively try the woocommerce_checkout_update_order_meta action hook (2 args):

add_action( 'woocommerce_checkout_update_order_meta', 'order_processed_with_pending_status', 10, 2 );
function order_processed_with_pending_status( $order_id, $data ) {
    error_log('Triggered');
}

两者都应该起作用……

这篇关于WooCommerce订单状态挂钩未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆