如何在网址中发送订单ID并获得响应?

时间:2020-06-09 11:46:46

标签: php wordpress woocommerce wordpress-rest-api woocommerce-rest-api

这是我的代码,执行此代码后,出现此错误“ Response:{“ Message”:“未找到与请求URI'http://example.com/Api/WooCommerceApi/SaveSubscriptionAndZoomData'相匹配的HTTP资源。”,“ MessageDetail”:“在与请求匹配的控制器“ WooCommerceApi”上未找到任何操作。“}”

function my_api_call( $order_id ){

    // Order Setup Via WooCommerce

    $order = new WC_Order( $order_id );

    // Iterate Through Items

    $items = $order->get_items();

    $url = "http://example.com/Api/WooCommerceApi/SaveSubscriptionAndZoomData";

    $orderid = "OrderId=".$order_id;

    $ch = curl_init( $url );
    curl_setopt( $ch, CURLOPT_POST, 1);
    curl_setopt( $ch, CURLOPT_POSTFIELDS, $orderid);
    curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt( $ch, CURLOPT_HEADER, 0);
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

    $response = curl_exec( $ch );

     write_log ("Order Id for new user: " .$orderid ." and Response is : ".$response);

     }
     add_action( 'woocommerce_payment_complete', 'my_api_call');

希望您会对此有所疑问。我想打印杰森 文件中也有响应

0 个答案:

没有答案