Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableDataStore::order_existspublicWC 8.0.0

Check if an order exists by id.

Method of the class: OrdersTableDataStore{}

No Hooks.

Returns

true|false. True if an order exists with the given name.

Usage

$OrdersTableDataStore = new OrdersTableDataStore();
$OrdersTableDataStore->order_exists( $order_id ): bool;
$order_id(int) (required)
The order id to check.

Changelog

Since 8.0.0 Introduced.

OrdersTableDataStore::order_exists() code WC 10.8.1

public function order_exists( $order_id ): bool {
	global $wpdb;

	// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
	$exists = $wpdb->get_var(
		$wpdb->prepare(
			"SELECT EXISTS (SELECT id FROM {$this->orders_table_name} WHERE id=%d)",
			$order_id
		)
	);
	// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared

	return (bool) $exists;
}