WooCommerce how to receive WebHooks data?

I'm new in WooCommerce WebHooks development.

I also tried to save webhooks triggered value into a file.

$json = file_get_contents('php://input');
$action = json_decode($json, true);

$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = $action;
fwrite($myfile, $txt);

fclose($myfile);

But I doesn't triggeged to my code.

Upvotes: 0

Views: 2773

Answers (1)

Solved it:

<?php
$webhookContent = "";



$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");

$webhook = fopen('php://input' , 'rb');
    while (!feof($webhook)) {
        $webhookContent .= fread($webhook, 4096);
    }


$txt = $webhookContent;
fwrite($myfile, $txt);

fclose($myfile);

?>

Upvotes: 2

Related Questions