wc_orders_count

Return the orders count of a specific order status.

Description

(int) wc_orders_count( (string) $status ); 

Returns (int)

Parameters (1)

0. $status (string)
The status.

Usage

  1. if ( !function_exists( 'wc_orders_count' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-order-functions.php'; 
  3.  
  4. // The status. 
  5. $status = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_orders_count($status); 
  9.  

Defined (1)

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

/includes/wc-order-functions.php  
  1. function wc_orders_count( $status ) { 
  2. $count = 0; 
  3. $status = 'wc-' . $status; 
  4. $order_statuses = array_keys( wc_get_order_statuses() ); 
  5.  
  6. if ( ! in_array( $status, $order_statuses ) ) { 
  7. return 0; 
  8.  
  9. $cache_key = WC_Cache_Helper::get_cache_prefix( 'orders' ) . $status; 
  10. $cached_count = wp_cache_get( $cache_key, 'counts' ); 
  11.  
  12. if ( false !== $cached_count ) { 
  13. return $cached_count; 
  14.  
  15. foreach ( wc_get_order_types( 'order-count' ) as $type ) { 
  16. $data_store = WC_Data_Store::load( 'shop_order' === $type ? 'order' : $type ); 
  17. if ( $data_store ) { 
  18. $count += $data_store->get_order_count( $status ); 
  19.  
  20. wp_cache_set( $cache_key, $count, 'counts' ); 
  21.  
  22. return $count;