Php WooCommerce钩子在Biiling表单完成后,在支付网关之前

Php WooCommerce钩子在Biiling表单完成后,在支付网关之前,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,在Woocommerce中,我需要在客户端完成账单表单之后调用一个函数,但在支付网关之前。此功能需要使用帐单表单信息。。。 有钩子吗 我试着用: add_action( 'woocommerce_order_status_changed', 'create_contact_and_deal', 10, 1 ); function create_contact_and_deal($order_id=0, $status_transition_from="", $status_transition_

在Woocommerce中,我需要在客户端完成账单表单之后调用一个函数,但在支付网关之前。此功能需要使用帐单表单信息。。。 有钩子吗

我试着用:

add_action( 'woocommerce_order_status_changed', 'create_contact_and_deal', 10, 1 );
function create_contact_and_deal($order_id=0, $status_transition_from="", $status_transition_to="", $instance=NULL) { ... 

但是,当我完成帐单表单时,该函数未被调用。

您在设置添加操作时缺少参数

add_action( 'woocommerce_order_status_changed', 'create_contact_and_deal', 10, 1 );
function create_contact_and_deal($order_id=0, $status_transition_from="", $status_transition_to="", $instance=NULL) {

}
应该是:

function action_woocommerce_order_status_changed( $this_get_id, $this_status_transition_from, $this_status_transition_to, $instance ) { 
    // make action magic happen here...
    if($this_status_transition_from == "pending" && $this_status_transition_to == "processing") 
      //Perform stuff when condition is met. 
    {

} 

// add the action 
add_action( 'woocommerce_order_status_changed', 'action_woocommerce_order_status_changed', 10, 4 ); 

最重要的部分是add_action函数的第四个参数。在您的示例中,1只传递第一个参数,ID。4将在每次更改时为您提供状态。最后一个值指示将向回调函数传递多少个参数

您可以查看订单状态挂钩。订单下单后处于“挂起”状态,这是在支付网关成功返回之前。当订单状态更新时,钩子将触发。您将需要条件逻辑来确保钩子只按您想要的方向触发。状态从->状态到。好LuckI尝试过这样做:添加动作“woocommerce\u order\u status\u changed”,“创建联系人和交易”,10,1;函数create_contact_and_deal$order_id=0,$status_transition_from=,$status_transition_to=,$instance=NULL{…但在我完成账单表单时未调用该函数。。。