好您可以为原始订单和克隆订单添加元数据。每次克隆项目时,只需为其添加+1即可。
function create_order( $original_order_id, ...
try {
$new_order = new WC_Order();
$new_order->set_props( array( ...
}
$original_order = wc_get_order( $original_order_id );
$order_item_num = $original_order->get_meta(\'_order_items_num\');
if($order_item_num >= 1) {
$new_order->update_meta_data( \'_order_item_num\', $order_item_num+1 );
$new_order->save();
$original_order->update_meta_data( \'_order_items_num\', $order_item_num+1 );
$original_order->save();
} else {
$new_order->update_meta_data( \'_order_item_num\', \'1\' );
$new_order->save();
$original_order->update_meta_data( \'_order_items_num\', \'1\' );
$original_order->save();
}
现在您可以修改订单号
add_filter( \'woocommerce_order_number\', \'change_woocommerce_order_number\', 1, 2);
function change_woocommerce_order_number( $order_id, $order ) {
$parent_id = $order->parent_id;
if($parent_id != 0) {
$parent_order = wc_get_order( $parent_id );
$order_sub_num = $order->get_meta(\'_order_item_num\');
return $parent_id . \'-\' . $order_sub_num;
}
return $order->id;
}