Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableDataStore::delete()publicWC 1.0

Method to delete an order from the database.

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

Return

null. Nothing.

Usage

$OrdersTableDataStore = new OrdersTableDataStore();
$OrdersTableDataStore->delete( $order, $args );
$order(\WC_Abstract_Order) (required) (passed by reference — &)
Order object.
$args(array)
Array of args to pass to the delete method.
Default: array()

Code of OrdersTableDataStore::delete() WC 7.1.0

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;
		}

		/**
		 * Fires immediately before an order is deleted from the database.
		 *
		 * @since 7.1.0
		 *
		 * @param int      $order_id ID of the order about to be deleted.
		 * @param WC_Order $order    Instance of the order that is about to be deleted.
		 */
		do_action( 'woocommerce_before_delete_order', $order_id, $order );

		// 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 {
		/**
		 * Fires immediately before an order is trashed.
		 *
		 * @since 7.1.0
		 *
		 * @param int      $order_id ID of the order about to be deleted.
		 * @param WC_Order $order    Instance of the order that is about to be deleted.
		 */
		do_action( 'woocommerce_before_trash_order', $order_id, $order );

		$this->trash_order( $order );

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