WooCommerce在完成Biiling表单之后且在付款网关之前挂钩

时间:2020-02-11 15:07:53

标签: 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_to="", $instance=NULL) { ... 

但是当我填写帐单时没有调用该函数。

1 个答案:

答案 0 :(得分:1)

设置add_action时缺少参数。

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会在每次更改时为您提供状态。最后一个值指示有多少参数将传递给您的回调函数。

相关问题