1 回答

TA貢獻1876條經(jīng)驗 獲得超7個贊
如果您希望在每個訂單上觸發(fā)此功能,請使用 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
}
我就是這樣處理的??赡苄枰鶕?jù)特定需求和任何錯誤進行調(diào)整,因為它完全沒有經(jīng)過測試
- 1 回答
- 0 關(guān)注
- 118 瀏覽
添加回答
舉報