From f4ec9a76659a2ee26e8aad908d5cee02b89ea0a8 Mon Sep 17 00:00:00 2001 From: Paul Sealock Date: Tue, 12 Mar 2019 16:51:47 +1300 Subject: [PATCH] products/stats: filter segmented products by category --- .../includes/class-wc-admin-reports-segmenting.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-segmenting.php b/plugins/woocommerce-admin/includes/class-wc-admin-reports-segmenting.php index 09b8b57a18c..4b761f2dde9 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-segmenting.php +++ b/plugins/woocommerce-admin/includes/class-wc-admin-reports-segmenting.php @@ -311,11 +311,19 @@ class WC_Admin_Reports_Segmenting { 'limit' => -1, ); - // @todo: filter by categories if $this->query_args['categories'] is set. if ( isset( $this->query_args['product_includes'] ) ) { $args['include'] = $this->query_args['product_includes']; } + if ( isset( $this->query_args['categories'] ) ) { + $categories = $this->query_args['categories']; + $args['category'] = array(); + foreach ( $categories as $category_id ) { + $terms = get_term_by( 'id', $category_id, 'product_cat' ); + $args['category'] = $terms->slug; + } + } + $segment_objects = wc_get_products( $args ); foreach ( $segment_objects as $segment ) { $id = $segment->get_id();