WooCommerce 支付完成挂钩 [英] WooCommerce payment complete hook

查看:33
本文介绍了WooCommerce 支付完成挂钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过长时间的搜索,我找到了这篇文章:

After a long search, I found this post:

WooCommerce 挂钩付款完成后"动作

其中讨论了在 WooCommerce 中创建 Web 挂钩以通知脚本执行...某事...无关紧要.

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

我还阅读了我在 WooCommerce 文档中可以找到的所有内容.

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.

我的目标是收到付款完成通知,然后在购买后将用户移动到不同的列表(客户列表而不是潜在客户列表) - 我在内部使用 PHPlist 作为我的列表管理器.很确定我可以处理那部分,如果我能让听众继续……

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.

我也发现了这个:

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

推荐答案

woocommerce_payment_complete 钩子在付款完成时被触发.传递的唯一变量是订单 ID,但您可以从中获取订单对象,并最终获取用户.

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
    }
}

这篇关于WooCommerce 支付完成挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆