在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) { ...
但是当我填写帐单时没有调用该函数。
答案 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
会在每次更改时为您提供状态。最后一个值指示有多少参数将传递给您的回调函数。