WC_Report_Sales_By_Product::get_chart_legend()publicWC 1.0

Get the legend for the main chart sidebar.

Метод класса: WC_Report_Sales_By_Product{}

Хуков нет.

Возвращает

Массив.

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

$WC_Report_Sales_By_Product = new WC_Report_Sales_By_Product();
$WC_Report_Sales_By_Product->get_chart_legend();

Код WC_Report_Sales_By_Product::get_chart_legend() WC 9.4.2

public function get_chart_legend() {

	if ( empty( $this->product_ids ) ) {
		return array();
	}

	$legend = array();

	$total_sales = $this->get_order_report_data(
		array(
			'data'         => array(
				'_line_total' => array(
					'type'            => 'order_item_meta',
					'order_item_type' => 'line_item',
					'function'        => 'SUM',
					'name'            => 'order_item_amount',
				),
			),
			'where_meta'   => array(
				'relation' => 'OR',
				array(
					'type'       => 'order_item_meta',
					'meta_key'   => array( '_product_id', '_variation_id' ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
					'meta_value' => $this->product_ids, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
					'operator'   => 'IN',
				),
			),
			'query_type'   => 'get_var',
			'filter_range' => true,
			'order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
		)
	);

	$total_items = absint(
		$this->get_order_report_data(
			array(
				'data'         => array(
					'_qty' => array(
						'type'            => 'order_item_meta',
						'order_item_type' => 'line_item',
						'function'        => 'SUM',
						'name'            => 'order_item_count',
					),
				),
				'where_meta'   => array(
					'relation' => 'OR',
					array(
						'type'       => 'order_item_meta',
						'meta_key'   => array( '_product_id', '_variation_id' ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
						'meta_value' => $this->product_ids, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
						'operator'   => 'IN',
					),
				),
				'query_type'   => 'get_var',
				'filter_range' => true,
				'order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
			)
		)
	);

	$legend[] = array(
		/* translators: %s: total items sold */
		'title'            => sprintf( __( '%s sales for the selected items', 'woocommerce' ), '<strong>' . wc_price( $total_sales ) . '</strong>' ),
		'color'            => $this->chart_colours['sales_amount'],
		'highlight_series' => 1,
	);

	$legend[] = array(
		/* translators: %s: total items purchased */
		'title'            => sprintf( __( '%s purchases for the selected items', 'woocommerce' ), '<strong>' . ( $total_items ) . '</strong>' ),
		'color'            => $this->chart_colours['item_count'],
		'highlight_series' => 0,
	);

	return $legend;
}