我想通过HTTP POST请求发送订单的详细信息(下订单时)(详细信息susch as firstName,lastName,order name name et eft。
数据应发送到我的节点/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;
}
节点/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.log('new WC request');
console.log(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(),
)
)
);
}
});
有关更多详细信息 - 查看获取订单详细信息