Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableDataStore::get_order_id_by_order_key()publicWC 1.0

Finds an Order ID based on an order key.

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

No Hooks.

Return

Int. The ID of an order, or 0 if the order could not be found

Usage

$OrdersTableDataStore = new OrdersTableDataStore();
$OrdersTableDataStore->get_order_id_by_order_key( $order_key );
$order_key(string) (required)
An order key has generated by.

Code of OrdersTableDataStore::get_order_id_by_order_key() WC 7.1.0

public function get_order_id_by_order_key( $order_key ) {
	global $wpdb;

	$orders_table = self::get_orders_table_name();
	$op_table     = self::get_operational_data_table_name();

	// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
	return (int) $wpdb->get_var(
		$wpdb->prepare(
			"SELECT {$orders_table}.id FROM {$orders_table}
			INNER JOIN {$op_table} ON {$op_table}.order_id = {$orders_table}.id
			WHERE {$op_table}.order_key = %s",
			$order_key
		)
	);
	// phpcs:enable
}