wc_get_orders() – Standard way of retrieving orders based on certain parameters.

You appear to be a bot. Output may be restricted

Description

Standard way of retrieving orders based on certain parameters.

This function should be used for order retrieval so that when we move to custom tables, functions still work. Args and usage: https://github.com/woocommerce/woocommerce/wiki/wc_get_orders-and-WC_Order_Query

Usage

$WC_Order[]|stdClass = wc_get_orders( $args );

Parameters

$args
( array ) required – Array of args (above).

Returns

WC_Order[]|stdClass Number of pages and an array of order objects if paginate is true, or just an array of values.

Source

File name: woocommerce/includes/wc-order-functions.php
Lines:

1 to 42 of 42
function wc_get_orders( $args ) {
  $map_legacy = array(
    'numberposts'    => 'limit',
    'post_type'      => 'type',
    'post_status'    => 'status',
    'post_parent'    => 'parent',
    'author'         => 'customer',
    'email'          => 'billing_email',
    'posts_per_page' => 'limit',
    'paged'          => 'page',
  );

  foreach ( $map_legacy as $from => $to ) {
    if ( isset( $args[ $from ] ) ) {
      $args[ $to ] = $args[ $from ];
    }
  }

  // Map legacy date args to modern date args.
  $date_before = false;
  $date_after  = false;

  if ( ! empty( $args['date_before'] ) ) {
    $datetime    = wc_string_to_datetime( $args['date_before'] );
    $date_before = strpos( $args['date_before'], ':' ) ? $datetime->getOffsetTimestamp() : $datetime->date( 'Y-m-d' );
  }
  if ( ! empty( $args['date_after'] ) ) {
    $datetime   = wc_string_to_datetime( $args['date_after'] );
    $date_after = strpos( $args['date_after'], ':' ) ? $datetime->getOffsetTimestamp() : $datetime->date( 'Y-m-d' );
  }

  if ( $date_before && $date_after ) {
    $args['date_created'] = $date_after . '...' . $date_before;
  } elseif ( $date_before ) {
    $args['date_created'] = '<' . $date_before;
  } elseif ( $date_after ) {
    $args['date_created'] = '>' . $date_after;
  }

  $query = new WC_Order_Query( $args );
  return $query->get_orders();
}
 

 View on GitHub View on Trac