Я хочу отправить детали заказа (когда заказ размещен) через HTTP-запрос POST (подробности, такие как имя, фамилия, имя заказа и т. д.).
Данные должны быть отправлены на мой сервер Node/Express и должны быть в формате JSON.
Вот мой файл functions.php:
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:
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.info('new WC request');
console.info(req.body);
});
module.exports = router;
Любая помощь приветствуется.






add_action( 'woocommerce_thankyou', function( $order_id ){
$order = new WC_Order( $order_id );
if ( $order->status != 'failed' ) {
$url = "https://www.test.com";
$response = wp_remote_post(
$url,
array(
'body' => array(
'firstname' => $order->get_billing_address_1(),
'lastname' => $order->get_billing_address_2(),
)
)
);
}
});
Чтобы узнать больше, проверьте Получить детали заказа.