Automattic\WooCommerce\Internal\DataStores\Orders
OrdersTableDataStore::handle_order_deletion_with_sync_disabled
Handles the deletion of an order from the orders table when sync is disabled:
If the corresponding row in the posts table is of placeholder type, it's just deleted; otherwise a "deleted_from" record is created in the meta table and the sync process will detect these and take care of deleting the appropriate post records.
Method of the class: OrdersTableDataStore{}
No Hooks.
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->handle_order_deletion_with_sync_disabled( $order_id ): void;
- $order_id(int) (required)
- Th id of the order that has been deleted from the orders table.
OrdersTableDataStore::handle_order_deletion_with_sync_disabled() OrdersTableDataStore::handle order deletion with sync disabled code WC 10.7.0
protected function handle_order_deletion_with_sync_disabled( $order_id ): void {
global $wpdb;
$post_type = $wpdb->get_var(
$wpdb->prepare( "SELECT post_type FROM {$wpdb->posts} WHERE ID=%d", $order_id )
);
if ( DataSynchronizer::PLACEHOLDER_ORDER_POST_TYPE === $post_type ) {
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->posts} WHERE ID=%d OR post_parent=%d",
$order_id,
$order_id
)
);
clean_post_cache( $order_id );
} else {
// phpcs:disable WordPress.DB.SlowDBQuery
$wpdb->insert(
self::get_meta_table_name(),
array(
'order_id' => $order_id,
'meta_key' => DataSynchronizer::DELETED_RECORD_META_KEY,
'meta_value' => DataSynchronizer::DELETED_FROM_ORDERS_META_VALUE,
)
);
// phpcs:enable WordPress.DB.SlowDBQuery
// Note that at this point upshift_or_delete_child_orders will already have been invoked,
// thus all the child orders either still exist but have a different parent id,
// or have been deleted and got their own deletion record already.
// So there's no need to do anything about them.
}
}