WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WC_REST_Report_Top_Sellers_V1_Controller::get_items() public WC 1.0

Get sales reports.

{} Это метод класса: WC_REST_Report_Top_Sellers_V1_Controller{}

Хуков нет.

Возвращает

Массив/WP_Error.

Использование

$WC_REST_Report_Top_Sellers_V1_Controller = new WC_REST_Report_Top_Sellers_V1_Controller();
$WC_REST_Report_Top_Sellers_V1_Controller->get_items( $request );
$request(WP_REST_Request) (обязательный)

Код WC_REST_Report_Top_Sellers_V1_Controller::get_items() WC 4.7.0

<?php
public function get_items( $request ) {
	// Set date filtering.
	$filter = array(
		'period'   => $request['period'],
		'date_min' => $request['date_min'],
		'date_max' => $request['date_max'],
	);
	$this->setup_report( $filter );

	$report_data = $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 = array();

	foreach ( $report_data as $item ) {
		$product = wc_get_product( $item->product_id );

		if ( $product ) {
			$top_sellers[] = array(
				'name'      => $product->get_name(),
				'product_id' => (int) $item->product_id,
				'quantity'   => wc_stock_amount( $item->order_item_qty ),
			);
		}
	}

	$data = array();
	foreach ( $top_sellers as $top_seller ) {
		$item   = $this->prepare_item_for_response( (object) $top_seller, $request );
		$data[] = $this->prepare_response_for_collection( $item );
	}

	return rest_ensure_response( $data );
}