首页 > 解决方案 > PHP Webhook 请求

问题描述

我正在运行一个带有 WooCommerce 结帐功能的 WordPress 网站。在结帐页面,我使用 webhook woocommerce_thankyou作为我的代码的登机点。此时,我正在从新订单中选择一些数据,以通过 webhook 将数据发送到另一个网站。我通过自定义 WordPress 插件集成了代码。目前,webhook 向我返回了以下错误:“DigiMember - Webhook Checkout (#1): the E-Mail-Adress will not send as GET- or POST-Parameter.”

可能是什么问题呢?

<?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;
?>

标签: phpwordpresswoocommercewebhooks

解决方案


推荐阅读