Update WC API v1 and v2 to use post_author instead of _customer_user

This commit is contained in:
Rodrigo Primo 2018-05-07 17:37:31 -03:00
parent b97f2749d6
commit fdfe95b07e
2 changed files with 26 additions and 16 deletions

View File

@ -359,15 +359,20 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
} }
if ( isset( $request['customer'] ) ) { if ( isset( $request['customer'] ) ) {
if ( ! empty( $args['meta_query'] ) ) { // On WC 3.5.0 the ID of the user that placed the order was moved from the post meta _customer_user to the post_author field in the wp_posts table.
$args['meta_query'] = array(); // WPCS: slow query ok. if ( version_compare( get_option( 'woocommerce_db_version' ), '3.5.0', '>=' ) ) {
} $args['author'] = $request['customer'];
} else {
if ( ! empty( $args['meta_query'] ) ) {
$args['meta_query'] = array(); // WPCS: slow query ok.
}
$args['meta_query'][] = array( $args['meta_query'][] = array(
'key' => '_customer_user', 'key' => '_customer_user',
'value' => $request['customer'], 'value' => $request['customer'],
'type' => 'NUMERIC', 'type' => 'NUMERIC',
); );
}
} }
// Search by product. // Search by product.

View File

@ -404,15 +404,20 @@ class WC_REST_Orders_V1_Controller extends WC_REST_Posts_Controller {
} }
if ( isset( $request['customer'] ) ) { if ( isset( $request['customer'] ) ) {
if ( ! empty( $args['meta_query'] ) ) { // On WC 3.5.0 the ID of the user that placed the order was moved from the post meta _customer_user to the post_author field in the wp_posts table.
$args['meta_query'] = array(); if ( version_compare( get_option( 'woocommerce_db_version' ), '3.5.0', '>=' ) ) {
} $args['author'] = $request['customer'];
} else {
if ( ! empty( $args['meta_query'] ) ) {
$args['meta_query'] = array(); // WPCS: slow query ok.
}
$args['meta_query'][] = array( $args['meta_query'][] = array(
'key' => '_customer_user', 'key' => '_customer_user',
'value' => $request['customer'], 'value' => $request['customer'],
'type' => 'NUMERIC', 'type' => 'NUMERIC',
); );
}
} }
// Search by product. // Search by product.