我想在下订单时用 orderid 调用 api?

I want to call api with orderid when order is placed?

Here Is My code

add_action( 'woocommerce_payment_complete', 'my_api_call');
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?".$order;
 }

请用你的知识帮助我。 谢谢

您目前没有向任何地方发送 URL。

您应该使用 curl 来 post 这个 URL 以及您需要的任何变量。但是,您还试图 post 一个根本不起作用的完整订单。

我不确定您的 API/system 对您的网站有什么要求,但如果您只想发送订单 ID,那么它应该如下所示:

add_action( 'woocommerce_payment_complete', 'my_api_call');
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 );

 }

$response 应该会给你留言。重要提示:此代码未经测试,但您应该可以从此处获得解决方案。

来源:POST data to a URL in PHP