PHP Запрос Webhook - PullRequest
       21

PHP Запрос Webhook

1 голос
/ 13 января 2020

У меня сайт WordPress с проверкой WooCommerce. На странице оформления заказа я использую webhook woocommerce_thankyou в качестве места для отправки моего кода. На данный момент я выбираю некоторые данные из нового моего заказа, чтобы отправить данные на другой веб-сайт через веб-крючок. Я интегрировал код поверх пользовательского плагина WordPress. В данный момент webhook возвращает мне следующую ошибку: «DigiMember - Checkout Webhook (# 1): адрес электронной почты не будет посылаться как GET- или POST-параметр».

В чем может быть проблема?

<?php
    function test ($order_id) {
?>

<span>
            woocommerce_thankyou
             <?php echo $order_id;
             $order=wc_get_order($order_id);
             echo $order->get_meta('digi_first_name');
             echo $order->get_meta('digi_last_name');
             echo $order->get_meta('digi_email');

             ?>
        </span>
        <?php
//The url you wish to send the POST request to
$url = 'https://traumjob-campus.de/member?dm_webhook=1_DCqtx6Xre1oM7tuKyon5rVzAIUWvVVXofMqTRQjE9JVDgf7gLI3M198bIeD5';

//The data you want to send via POST
$fields = [
    'digi_first_name'      => 'user',
    'digi_last_name' => 'test',
    'digi_email'         => 'test@user.de'
];

//url-ify the data for the POST
$fields_string = http_build_query($fields);

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//So that curl_exec returns the contents of the cURL; rather than echoing it
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 

//execute post
$result = curl_exec($ch);
echo $result;
?>
...