Aar*_*umm 21 webhooks woocommerce
经过长时间的搜索,我找到了这篇文章:
谈论在woocommerce中创建webhooks以通知脚本做...某事......并不重要.
我还阅读了我在woocommerce docs中可以找到的所有内容.
但是我需要一些关于在另一端实际编写处理程序的文档或指导.
我的目标是收到付款完成通知,然后在购买后将用户移动到不同的列表(客户列表而不是潜在客户列表) - 我在内部使用PHPlist作为我的列表管理器.我很确定我可以处理那部分,如果我能让听众继续...
但是..我不知道Web钩子发送了什么,如何让它发送我想要的数据,以及如何处理监听器.
我也发现了这个:
哪 - 可能有用吗?我仍然不确定从哪里开始听,或者如果这篇文章仍有效,鉴于它已经有几年了......
谢谢!
- 亚伦
hel*_*ing 30
在woocommerce_payment_complete完成付款时钩被激发.传递的唯一变量是订单ID,但是您可以从中获取订单对象,最终获得用户.
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
}
}
Run Code Online (Sandbox Code Playgroud)
在@helgatheviking和@Scriptonomy的帮助下,我决定使用这个代码,在woocommerce-> settings-> api-> webhooks中没有启用webhook:
add_action( 'woocommerce_payment_complete', 'so_payment_complete' );
function so_payment_complete( $order_id ){
$order = wc_get_order( $order_id );
$billingEmail = $order->billing_email;
$products = $order->get_items();
foreach($products as $prod){
$items[$prod['product_id']] = $prod['name'];
}
$url = 'http://requestb.in/15gbo981';
// post to the request somehow
wp_remote_post( $url, array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'body' => array( 'billingemail' => $billingEmail, 'items' => $items ),
'cookies' => array()
)
);
Run Code Online (Sandbox Code Playgroud)
现在我只需编写监听器:)这是发送请求的主体(我可以在requestb.in上看到):
billingemail=%22aaron-buyer%40thirdoptionmusic.com%22&items%5B78%5D=Cult+Of+Nice&items%5B126%5D=Still&items%5B125%5D=The+Monkey+Set
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31017 次 |
| 最近记录: |