alejesus8
alejesus8

Reputation: 39

Get incoming webhook of woocommerce

I'm trying to receive a JSON of a woocommerce webhook in a tracker.php to manipulate the content, but something is wrong because it doesn't save anything in $_SESSION. This is my code ....

(!isset($_SESSION))? session_start() : null;

if($json = json_decode(file_get_contents("php://input"), true)) {
    $data = json_decode($json, true);
    $_SESSION["json"] = $data;
} else {
    var_dump($_SESSION["json"]);
}

tested the webhook with http://requestbin.fullcontact.com/ and received the content. here a capture

enter image description here

Upvotes: 0

Views: 1069

Answers (1)

Nauman Ahmad
Nauman Ahmad

Reputation: 320

issue is in this line

$data = json_decode($json, true);

here $json is array and jsondecode expect string.

here is code which will work.

 (!isset($_SESSION))? session_start() : null;

 if($json = json_decode(file_get_contents("php://input"), true)) {
  //this seection will execute if you post data.
  $_SESSION["json"] = $json;
 } else {
   //this will execute if you do not post data
   var_dump($_SESSION["json"]);
  }

Upvotes: 1

Related Questions