wc_get_orders

Wrapper for get_posts specific to orders.

Description

(array|stdClass) wc_get_orders( (array) $args ); 

This function should be used for order retrieval so that when we move to custom tables, functions still work.

Args: status array|string List of order statuses to find type array|string Order type, e.g. shop_order or shop_order_refund parent int post/order parent customer int|string|array User ID or billing email to limit orders to a particular user. Accepts array of values. Array of values is OR'ed. If array of array is passed, each array will be AND'ed. e.g. test@test.com, 1, array( 1, 2, 3 ), array( array( 1, test@test.com ), 2, 3 ) limit int Maximum of orders to retrieve. offset int Offset of orders to retrieve. page int Page of orders to retrieve. Ignored when using the offset arg. date_before string Get orders before a certain date ( strtotime() compatibile string ) date_after string Get orders after a certain date ( strtotime() compatibile string ) exclude array Order IDs to exclude from the query. orderby string Order by date, title, id, modified, rand etc order string ASC or DESC return string Type of data to return. Allowed values: ids array of order ids objects array of order objects (default) paginate bool If true, the return value will be an array with values: orders => array of data (return value above), total => total number of orders matching the query max_num_pages => max number of pages found

Returns (array|stdClass)

Number of pages and an array of order objects if paginate is true, or just an array of values.

Parameters (1)

0. $args (array)
Array of args (above)

Usage

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

Defined (1)

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

/includes/wc-order-functions.php  
  1. function wc_get_orders( $args ) { 
  2. $args = wp_parse_args( $args, array( 
  3. 'status' => array_keys( wc_get_order_statuses() ),  
  4. 'type' => wc_get_order_types( 'view-orders' ),  
  5. 'parent' => null,  
  6. 'customer' => null,  
  7. 'email' => '',  
  8. 'limit' => get_option( 'posts_per_page' ),  
  9. 'offset' => null,  
  10. 'page' => 1,  
  11. 'exclude' => array(),  
  12. 'orderby' => 'date',  
  13. 'order' => 'DESC',  
  14. 'return' => 'objects',  
  15. 'paginate' => false,  
  16. 'date_before' => '',  
  17. 'date_after' => '',  
  18. ) ); 
  19.  
  20. // Handle some BW compatibility arg names wherewp_queryargs differ in naming. 
  21. $map_legacy = array( 
  22. 'numberposts' => 'limit',  
  23. 'post_type' => 'type',  
  24. 'post_status' => 'status',  
  25. 'post_parent' => 'parent',  
  26. 'author' => 'customer',  
  27. 'posts_per_page' => 'limit',  
  28. 'paged' => 'page',  
  29. ); 
  30.  
  31. foreach ( $map_legacy as $from => $to ) { 
  32. if ( isset( $args[ $from ] ) ) { 
  33. $args[ $to ] = $args[ $from ]; 
  34.  
  35. return WC_Data_Store::load( 'order' )->get_orders( $args );