Automattic\WooCommerce\Internal\Admin\Orders

ListTable::do_delete()privateWC 1.0

Handles bulk trashing of orders.

Method of the class: ListTable{}

No Hooks.

Return

Int. Number of orders that were trashed.

Usage

// private - for code of main (parent) class only
$result = $this->do_delete( $ids, $force_delete ): int;
$ids(int[]) (required)
Order IDs to be trashed.
$force_delete(true|false)
When set, the order will be completed deleted. Otherwise, it will be trashed.
Default: false

ListTable::do_delete() code WC 7.1.0

private function do_delete( array $ids, bool $force_delete = false ): int {
	$orders_store = wc_get_container()->get( OrdersTableDataStore::class );
	$delete_args  = $force_delete ? array( 'force_delete' => true ) : array();
	$changed      = 0;

	foreach ( $ids as $id ) {
		$order = wc_get_order( $id );
		$orders_store->delete( $order, $delete_args );
		$updated_order = wc_get_order( $id );

		if ( ( $force_delete && false === $updated_order ) || ( ! $force_delete && $updated_order->get_status() === 'trash' ) ) {
			$changed++;
		}
	}

	return $changed;
}