WordPress at a glance
function is not described

WC_API_Reports::get_top_sellers_report() public WC 2.1

Get the top sellers report

{} It's a method of the class: WC_API_Reports{}

Hooks from the method
Return

Array|WP_Error.

Usage

$WC_API_Reports = new WC_API_Reports();
$WC_API_Reports->get_top_sellers_report( $fields, $filter );
$fields(string)
fields to include in response
$filter(array)
date filtering

Changelog

Since 2.1 Introduced.

Code of WC_API_Reports::get_top_sellers_report() WC 5.0.0

<?php
public function get_top_sellers_report( $fields = null, $filter = array() ) {

	// check user permissions
	$check = $this->validate_request();

	if ( is_wp_error( $check ) ) {
		return $check;
	}

	// set date filtering
	$this->setup_report( $filter );

	$top_sellers = $this->report->get_order_report_data( array(
		'data' => array(
			'_product_id' => array(
				'type'            => 'order_item_meta',
				'order_item_type' => 'line_item',
				'function'        => '',
				'name'            => 'product_id',
			),
			'_qty' => array(
				'type'            => 'order_item_meta',
				'order_item_type' => 'line_item',
				'function'        => 'SUM',
				'name'            => 'order_item_qty',
			),
		),
		'order_by'     => 'order_item_qty DESC',
		'group_by'     => 'product_id',
		'limit'        => isset( $filter['limit'] ) ? absint( $filter['limit'] ) : 12,
		'query_type'   => 'get_results',
		'filter_range' => true,
	) );

	$top_sellers_data = array();

	foreach ( $top_sellers as $top_seller ) {

		$product = wc_get_product( $top_seller->product_id );

		$top_sellers_data[] = array(
			'title'      => $product->get_name(),
			'product_id' => $top_seller->product_id,
			'quantity'   => $top_seller->order_item_qty,
		);
	}

	return array( 'top_sellers' => apply_filters( 'woocommerce_api_report_response', $top_sellers_data, $this->report, $fields, $this->server ) );
}