From e891e3ed7db5cfea50020debed6fde5130780c68 Mon Sep 17 00:00:00 2001 From: Boro Sitnikovski Date: Wed, 25 Apr 2018 01:40:29 +0100 Subject: [PATCH 1/2] Support payment_method_in when selecting orders --- .../class-wc-order-data-store-cpt.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/includes/data-stores/class-wc-order-data-store-cpt.php b/includes/data-stores/class-wc-order-data-store-cpt.php index 922ed2ec9e4..173a4ff5983 100644 --- a/includes/data-stores/class-wc-order-data-store-cpt.php +++ b/includes/data-stores/class-wc-order-data-store-cpt.php @@ -711,6 +711,24 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement } } + if ( ! empty( $query_vars['payment_method__in'] ) ) { + if ( ! is_array( $query_vars['payment_method__in'] ) ) { + $query_vars['payment_method__in'] = array( $query_vars['payment_method__in'] ); + } + + $payment_methods = array(); + + foreach ( $query_vars['payment_method__in'] as $value ) { + $payment_methods[] = array( + 'key' => '_payment_method', + 'value' => $value, + 'compare' => '=', + ); + } + + $wp_query_args['meta_query'][] = array_merge( array( 'relation' => 'OR' ), $payment_methods ); + } + if ( ! isset( $query_vars['paginate'] ) || ! $query_vars['paginate'] ) { $wp_query_args['no_found_rows'] = true; } From d6b4ca980c633832ada6776585d3ebcc30a7c96c Mon Sep 17 00:00:00 2001 From: Boro Sitnikovski Date: Thu, 26 Apr 2018 16:49:49 +0200 Subject: [PATCH 2/2] Add support for arrays when building meta query args --- .../data-stores/class-wc-data-store-wp.php | 2 +- .../class-wc-order-data-store-cpt.php | 18 ------------------ 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/includes/data-stores/class-wc-data-store-wp.php b/includes/data-stores/class-wc-data-store-wp.php index 6dc127f6fb1..f2574772416 100644 --- a/includes/data-stores/class-wc-data-store-wp.php +++ b/includes/data-stores/class-wc-data-store-wp.php @@ -232,7 +232,7 @@ class WC_Data_Store_WP { $wp_query_args['meta_query'][] = array( 'key' => '_' . $key, 'value' => $value, - 'compare' => '=', + 'compare' => is_array( $value ) ? 'IN' : '=', ); } else { // Other vars get mapped to wp_query args or just left alone. $key_mapping = array( diff --git a/includes/data-stores/class-wc-order-data-store-cpt.php b/includes/data-stores/class-wc-order-data-store-cpt.php index 173a4ff5983..922ed2ec9e4 100644 --- a/includes/data-stores/class-wc-order-data-store-cpt.php +++ b/includes/data-stores/class-wc-order-data-store-cpt.php @@ -711,24 +711,6 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement } } - if ( ! empty( $query_vars['payment_method__in'] ) ) { - if ( ! is_array( $query_vars['payment_method__in'] ) ) { - $query_vars['payment_method__in'] = array( $query_vars['payment_method__in'] ); - } - - $payment_methods = array(); - - foreach ( $query_vars['payment_method__in'] as $value ) { - $payment_methods[] = array( - 'key' => '_payment_method', - 'value' => $value, - 'compare' => '=', - ); - } - - $wp_query_args['meta_query'][] = array_merge( array( 'relation' => 'OR' ), $payment_methods ); - } - if ( ! isset( $query_vars['paginate'] ) || ! $query_vars['paginate'] ) { $wp_query_args['no_found_rows'] = true; }