I want to send the details of an order (when the order is placed) via an HTTP POST request (details susch as firstname, lastname, order name etc.).
The data should be send to my Node/Express backend, and should be as JSON.
Here's my functions.php file:
add_action( 'woocommerce_order_status_completed', 'send_order_data' );
function send_order_data( $order_id ) {
$order = new WC_Order( $order_id );
$url = 'http://exemple.com/custom-url';
if ( $order->status != 'failed' ) {
//Get the order and customer data
//Send the data as a HTTP POST request && the data should be as JSON
exit;
}
Node/Express backend:
const express = require('express');
const router = express.Router();
// @route POST '/api'
// @desc
// @access Public
router.post('/', (req, res) => {
// Get data from WC post request
console.log('new WC request');
console.log(req.body);
});
module.exports = router;
Any help would be much appreciated.