Use wc_get_orders() to query customer orders

This commit is contained in:
Claudio Sanches 2016-11-17 22:11:05 -02:00
parent aba4699ee2
commit 4fd47e1b02
2 changed files with 18 additions and 18 deletions

View File

@ -249,20 +249,21 @@ class WC_API_Customers extends WC_API_Resource {
$id = $this->validate_request( $id, 'customer', 'read' );
if ( is_wp_error( $id ) )
if ( is_wp_error( $id ) ) {
return $id;
}
$order_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id
FROM $wpdb->posts AS posts
LEFT JOIN {$wpdb->postmeta} AS meta on posts.ID = meta.post_id
WHERE meta.meta_key = '_customer_user'
AND meta.meta_value = '%s'
AND posts.post_type = 'shop_order'
AND posts.post_status = IN ( '" . implode( "','", array_keys( wc_get_order_statuses() ) ) . "' )
", $id ) );
$order_ids = wc_get_orders( array(
'customer' => $id,
'limit' => -1,
'orderby' => 'date',
'order' => 'ASC',
'return' => 'ids',
) );
if ( empty( $order_ids ) )
if ( empty( $order_ids ) ) {
return array( 'orders' => array() );
}
$orders = array();

View File

@ -461,14 +461,13 @@ class WC_API_Customers extends WC_API_Resource {
return $id;
}
$order_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id
FROM $wpdb->posts AS posts
LEFT JOIN {$wpdb->postmeta} AS meta on posts.ID = meta.post_id
WHERE meta.meta_key = '_customer_user'
AND meta.meta_value = '%s'
AND posts.post_type = 'shop_order'
AND posts.post_status IN ( '" . implode( "','", array_keys( wc_get_order_statuses() ) ) . "' )
", $id ) );
$order_ids = wc_get_orders( array(
'customer' => $id,
'limit' => -1,
'orderby' => 'date',
'order' => 'ASC',
'return' => 'ids',
) );
if ( empty( $order_ids ) ) {
return array( 'orders' => array() );