How to get variable for a customer from a webhook in WooCommerce

让人想犯罪 __ 提交于 2019-12-13 21:49:52

问题


I am using WooCommerce Subscriptions, and have created a web hook for when a customer cancels their subscription...

I want to update a MySQL database record from 'Publish' to 'Delete' upon this event occurring. I have created a new page for it etc. in a delivery URL.

FORM/POST PARAMETERS

webhook_id: 4099
HEADERS

Cf-Connecting-Ip: 212.227.29.24
Content-Length: 15
Total-Route-Time: 0
Host: requestb.in
Accept: */*
Cf-Visitor: {"scheme":"https"}
Accept-Encoding: gzip
Referer: https://requestb.in/sqwf1tsq
User-Agent: WooCommerce/3.1.2 Hookshot (WordPress/4.8.1)
Connect-Time: 1
Content-Type: application/x-www-form-urlencoded
Cf-Ray: 39d5a75dc8980f45-FRA
X-Request-Id: e1b16cd7-fb41-471b-9c47-dce0dd7260cc
Cf-Ipcountry: DE
Via: 1.1 vegur
Connection: close
RAW BODY

webhook_id=4099

But... how do I get any variables from a web hook payload? Its so confusing (newbie here!). I'd like to get either the username or a variable called 'barcode' which is stored for each user/customer, which I can then identify in the separate database and make the change.

Hope that makes sense..!

Help would be appreciated, Many thanks!!


回答1:


The function you have responding to the webhook should listen for the php input stream.

$input = @file_get_contents("php://input");
var_dump($input); //this will output everything sent to your webhook

From here, you can see which properties you'll want to grab.



来源:https://stackoverflow.com/questions/46185409/how-to-get-variable-for-a-customer-from-a-webhook-in-woocommerce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!