Sending Data via cURL to External Order Management System Sending Data via cURL to External Order Management System curl curl

Sending Data via cURL to External Order Management System


If you want this to fire on every order use one of WooCommerces hooks and place it in your functions.php file.

add_action( 'woocommerce_thankyou', 'so_woocommerce_thankyou' );function so_woocommerce_thankyou( $order_id ) {    $Order = new WP_Order( $order_id );    // Build your item sku and qty array    $payloadItems = [];    foreach( $Order->get_items() as $item ) {        $product = wc_get_product( $item->get_product_id );        $payloadItems[] = [$product->get_sku(), $item->get_quantity()];    }        // Reserve    $reservations = [];    if( count( $payloadItems ) ) {        foreach( $payloadItems as $item ) {            $reservations[] = reserveArticle( $item[0], $item[1] );        }    }    // Send sales order    $salesOrder = false;    if( count( $reservations ) ) {        $salesOrder = sendSalesOrder( $Order, $reservations );    }    if( $salesOrder !== false ) {      // Success    } else {      // Something went wrong    }}function reserveArticle( $sku, $qty ) {    // The cURL request to reserve an article.    // Pipe in the required information into your postfields value return response}function sendSalesOrder( $reservation, $Order ) {    // The cURL request to send a sales order.    // Pipe in the required information into your postfields value return response or false on error}

That's how I would approach it. Might need to be tweaked for specific needs and any errors as it's completely not tested.


I can see this being one in two ways.

  1. Use JS and make an AJAX call once that is complete you can submit the form.
  2. Encapsulate the Curl request on methods and chuck them in when a user press submit.

Not a concrete idea but hopefully it can give you can idea on how to approach it.