首页 > 解决方案 > Biiling 表单完成后,支付网关之前的 WooCommerce Hook

问题描述

在 Woocommerce 中,我需要在客户端完成计费表单之后、支付网关之前调用一个函数。此功能需要使用计费表单信息...是否有一个 Hook ?

我试图这样做:

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) { ... 

但是当我完成计费表格时没有调用该函数..

标签: phpwordpresswoocommerce

解决方案


设置 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每次更改时都会为​​您提供状态。最后一个值表示将传递给回调函数的参数数量。


推荐阅读