OrdersTableDataStore::get_order_id_by_order_key()publicWC 1.0

Finds an Order ID based on an order key.

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

No Hooks.


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


$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(
			"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",
	// phpcs:enable