How to get variable for a customer from a webhook

2019-09-19 08:26发布

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条回答
Bombasti
2楼-- · 2019-09-19 09:19

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.

查看更多
登录 后发表回答