From 14a12172186fa66ac316d8b90cf5ffefc4a013ad Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 8 Sep 2018 22:45:51 -0300 Subject: [PATCH] Load all product types even when empty --- .../class-wc-rest-report-products-totals-controller.php | 8 +++++++- tests/unit-tests/api/reports-products-totals.php | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/includes/api/class-wc-rest-report-products-totals-controller.php b/includes/api/class-wc-rest-report-products-totals-controller.php index 23ab703ea6f..63812219260 100644 --- a/includes/api/class-wc-rest-report-products-totals-controller.php +++ b/includes/api/class-wc-rest-report-products-totals-controller.php @@ -40,9 +40,15 @@ class WC_REST_Report_Products_Totals_Controller extends WC_REST_Reports_Controll */ protected function get_reports() { $types = wc_get_product_types(); + $terms = get_terms( + array( + 'taxonomy' => 'product_type', + 'hide_empty' => false, + ) + ); $data = array(); - foreach ( get_terms( 'product_type' ) as $product_type ) { + foreach ( $terms as $product_type ) { if ( ! isset( $types[ $product_type->name ] ) ) { continue; } diff --git a/tests/unit-tests/api/reports-products-totals.php b/tests/unit-tests/api/reports-products-totals.php index 28a40722358..fc903dbb5ea 100644 --- a/tests/unit-tests/api/reports-products-totals.php +++ b/tests/unit-tests/api/reports-products-totals.php @@ -41,9 +41,15 @@ class WC_Tests_API_Reports_Products_Totals extends WC_REST_Unit_Test_Case { $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/reports/products/totals' ) ); $report = $response->get_data(); $types = wc_get_product_types(); + $terms = get_terms( + array( + 'taxonomy' => 'product_type', + 'hide_empty' => false, + ) + ); $data = array(); - foreach ( get_terms( 'product_type' ) as $product_type ) { + foreach ( $terms as $product_type ) { if ( ! isset( $types[ $product_type->name ] ) ) { continue; }