Set child orders to be children of current order parent before deleting for consistency.

In post storage, just before deleting an order, we will change all child order's parent to be parent of current order. This commit adds the same behavior for HPOS for consistency.
This commit is contained in:
Vedanshu Jain 2022-12-28 16:09:13 +05:30
parent 8c3f06c452
commit 44757082d0
1 changed files with 15 additions and 0 deletions

View File

@ -1766,7 +1766,9 @@ FROM $order_meta_table
*/ */
do_action( 'woocommerce_before_delete_order', $order_id, $order ); do_action( 'woocommerce_before_delete_order', $order_id, $order );
$this->unlink_child_orders( $order );
$this->delete_order_data_from_custom_order_tables( $order_id ); $this->delete_order_data_from_custom_order_tables( $order_id );
$order->set_id( 0 ); $order->set_id( 0 );
// If this datastore method is called while the posts table is authoritative, refrain from deleting post data. // If this datastore method is called while the posts table is authoritative, refrain from deleting post data.
@ -1796,6 +1798,19 @@ FROM $order_meta_table
} }
} }
private function unlink_child_orders( $order ) {
global $wpdb;
$order_table = self::get_orders_table_name();
$order_parent = $order->get_parent_id();
$wpdb->update(
$order_table,
array( 'parent_order_id' => $order_parent ),
array( 'parent_order_id' => $order->get_id() ),
array( '%d' ),
array( '%d' )
);
}
/** /**
* Trashes an order. * Trashes an order.
* *