WC_REST_Report_Products_Totals_Controller::get_reports()protectedWC 3.5.0

Get reports list.

Method of the class: WC_REST_Report_Products_Totals_Controller{}

No Hooks.

Return

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_reports();

Changelog

Since 3.5.0 Introduced.

WC_REST_Report_Products_Totals_Controller::get_reports() code WC 8.6.1

protected function get_reports() {
	$types = wc_get_product_types();
	$terms = get_terms(
		array(
			'taxonomy'   => 'product_type',
			'hide_empty' => false,
		)
	);
	$data  = array();

	foreach ( $terms as $product_type ) {
		if ( ! isset( $types[ $product_type->name ] ) ) {
			continue;
		}

		$data[] = array(
			'slug'  => $product_type->name,
			'name'  => $types[ $product_type->name ],
			'total' => (int) $product_type->count,
		);
	}

	return $data;
}