wc_get_order_id_by_order_key

Finds an Order ID based on an order key.

Description

(int) wc_get_order_id_by_order_key( (string) $order_key ); 

Returns (int)

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

Parameters (1)

0. $order_key (string)
An order key has generated by

Usage

  1. if ( !function_exists( 'wc_get_order_id_by_order_key' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-order-functions.php'; 
  3.  
  4. // An order key has generated by 
  5. $order_key = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_get_order_id_by_order_key($order_key); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-order-functions.php  
  1. function wc_get_order_id_by_order_key( $order_key ) { 
  2. $data_store = WC_Data_Store::load( 'order' ); 
  3. return $data_store->get_order_id_by_order_key( $order_key );