WordPress at Your Fingertips
function is not described

WC_Report_Sales_By_Category::get_chart_legend() public WC 1.0

Get the legend for the main chart sidebar.

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

No Hooks.

Return

Array.

Usage

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

Code of WC_Report_Sales_By_Category::get_chart_legend() WC 5.8.0

public function get_chart_legend() {

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

	$legend = array();
	$index  = 0;

	foreach ( $this->show_categories as $category ) {

		$category    = get_term( $category, 'product_cat' );
		$total       = 0;
		$product_ids = $this->get_products_in_category( $category->term_id );

		foreach ( $product_ids as $id ) {

			if ( isset( $this->item_sales[ $id ] ) ) {
				$total += $this->item_sales[ $id ];
			}
		}

		$legend[] = array(
			/* translators: 1: total items sold 2: category name */
			'title'            => sprintf( __( '%1$s sales in %2$s', 'woocommerce' ), '<strong>' . wc_price( $total ) . '</strong>', $category->name ),
			'color'            => isset( $this->chart_colours[ $index ] ) ? $this->chart_colours[ $index ] : $this->chart_colours[0],
			'highlight_series' => $index,
		);

		$index++;
	}

	return $legend;
}