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,6 +359,10 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
}
if ( isset( $request['customer'] ) ) {
// 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.
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.
}
@ -369,6 +373,7 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
'type' => 'NUMERIC',
);
}
}
// Search by product.
if ( ! empty( $request['product'] ) ) {

View File

@ -404,8 +404,12 @@ class WC_REST_Orders_V1_Controller extends WC_REST_Posts_Controller {
}
if ( isset( $request['customer'] ) ) {
// 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.
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();
$args['meta_query'] = array(); // WPCS: slow query ok.
}
$args['meta_query'][] = array(
@ -414,6 +418,7 @@ class WC_REST_Orders_V1_Controller extends WC_REST_Posts_Controller {
'type' => 'NUMERIC',
);
}
}
// Search by product.
if ( ! empty( $request['product'] ) ) {