0

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

Please help me with your knowledge. Thanks

Nicks9789
  • 13
  • 6
  • Can you explain further what you need to do? At the moment your `$url` contains the link with order id and you are not doing anything with it. Do you need to send the order id somewhere? – Fresz Jun 01 '20 at 10:27
  • ok, first I would recommend looking into documentation for this API - I am almost 99% sure it requires something like `/SaveSubscriptionAndZoomData?orderid=".$orderid;` otherwise the system won't pick it up (I might be wrong). – Fresz Jun 01 '20 at 10:35

1 Answers1

0

You are not sending the URL anywhere at the moment.

You should use curl to post this URL with any variables you need. However, you are also trying to post a full order which will not work at all.

I am not sure what your API/system requires from your website but if you want to send only the order ID then this should look something like this:

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

 }

The $response should give you a message. Important: this code is untested but you should be able to get the solution from here.

Source: POST data to a URL in PHP

Nicks9789
  • 13
  • 6
Fresz
  • 1,804
  • 2
  • 16
  • 29