Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableDataStore::delete()publicWC 1.0

Method to delete an order from the database.

{} Это метод класса: OrdersTableDataStore{}

Возвращает

null. Ничего.

Использование

$OrdersTableDataStore = new OrdersTableDataStore();
$OrdersTableDataStore->delete( $order, $args );
$order(WC_Order) (обязательный) (передается по ссылке — &)
Order object.
$args(массив)
Array of args to pass to the delete method.
По умолчанию: array()

Код OrdersTableDataStore::delete() WC 6.9.4

public function delete( &$order, $args = array() ) {
	$order_id = $order->get_id();

	if ( ! $order_id ) {
		return;
	}

	if ( ! empty( $args['force_delete'] ) ) {
		$this->delete_order_data_from_custom_order_tables( $order_id );
		$order->set_id( 0 );

		// If this datastore method is called while the posts table is authoritative, refrain from deleting post data.
		if ( ! is_a( $order->get_data_store(), self::class ) ) {
			return;
		}

		// Delete the associated post, which in turn deletes order items, etc. through {@see WC_Post_Data}.
		// Once we stop creating posts for orders, we should do the cleanup here instead.
		wp_delete_post( $order_id );

		do_action( 'woocommerce_delete_order', $order_id ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
	} else {
		$this->trash_order( $order );

		do_action( 'woocommerce_trash_order', $order_id ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
	}
}