1 回答
TA贡献1876条经验 获得超7个赞
如果您希望在每个订单上触发此功能,请使用 WooCommerces 挂钩之一并将其放置在您的functions.php文件中。
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
}
我就是这样处理的。可能需要根据特定需求和任何错误进行调整,因为它完全没有经过测试
- 1 回答
- 0 关注
- 83 浏览
添加回答
举报