Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
853 views
in Technique[技术] by (71.8m points)

webhooks - WooCommerce payment complete hook

After a long search, I found this post:

WooCommerce hook for "after payment complete" actions

which talks about creating web hooks in WooCommerce to notify a script to do...something...doesn't matter too much what.

I've also read everything I can find in WooCommerce docs.

but I need some kind of documentation or guidance on actually writing the handler on the other end.

My goal is to receive a payment complete notification and then move the user to a different list (a customer list rather than a prospects list) after purchase - I use PHPlist in house as my list manager. Pretty sure I can deal with that part, if I can just get the listener going...

But..I don't know what the web hook sends, how to get it to send data that I want, and what to do with the listener.

I did also find this:

https://wordpress.org/support/topic/plugin-woocommerce-excelling-ecommerce-order-id-for-payment-notification-to-external-webservice?replies=4

which - MIGHT be helpful? i'm still not sure where to begin with the listener, or if this post is valid still, given that it's a couple of years old...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The woocommerce_payment_complete hook is fired when the payment is completed. The only variable passed is the order id, though from that you can get the order object, and ultimately the user.

add_action( 'woocommerce_payment_complete', 'so_payment_complete' );
function so_payment_complete( $order_id ){
    $order = wc_get_order( $order_id );
    $user = $order->get_user();
    if( $user ){
        // do something with the user
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...