WooCommerce is a cool e-commerce plugin and powers many sites.
Here is how to retrieve some of the recent WooCommerce orders.
You can pull orders from today, last 7 days, last 30 days, current month or last year.
[code]
// today
$after_date = date( 'Y-m-d', strtotime('now') );
// Last 7 days
$after_date = date( 'Y-m-d', strtotime('-7 days') );
// Last 30 days
$after_date = date( 'Y-m-d', strtotime('-30 days') );
// This month
$after_date = date( 'Y-m-01', strtotime('now') );
// This year
$after_date = date( 'Y-01-01', strtotime('now') );
// 0 today
$args = array(
'post_type' => 'shop_order',
'post_status' => 'publish',
'posts_per_page' => 250, // or -1 for all
'tax_query' => array(
array(
'taxonomy' => 'shop_order_status',
'field' => 'slug',
'terms' => array('completed')
),
),
);
$args['date_query'] = array(
'after' => $after_date, //'2012-04-01',
'inclusive' => true,
);
$orders = get_posts($args);
[/code]
The result looks like this.
[code]
array (
0 =>
WP_Post::__set_state(array(
'ID' => 104,
'post_author' => '1',
'post_date' => '2014-10-12 02:06:00',
'post_date_gmt' => '2014-10-12 02:06:00',
'post_content' => '',
'post_title' => 'Order – October 12, 2014 @ 02:07 AM',
'post_excerpt' => '',
'post_status' => 'wc-completed',
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_password' => '',
'post_name' => 'order-october-12-2014-0207-am',
'to_ping' => '',
'pinged' => '',
'post_modified' => '2014-10-12 02:07:32',
'post_modified_gmt' => '2014-10-12 02:07:32',
'post_content_filtered' => '',
'post_parent' => 0,
'guid' => 'http://fakesite.com.clients.com/?post_type=shop_order&p=104',
'menu_order' => 0,
'post_type' => 'shop_order',
'post_mime_type' => '',
'comment_count' => '1',
'filter' => 'raw',
)),
)
[/code]
Related:
http://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters
http://wordpress.stackexchange.com/questions/10438/display-posts-starting-from-today-date