WC_Report_Sales_By_Product::get_chart_legend
Get the legend for the main chart sidebar.
Method of the class: WC_Report_Sales_By_Product{}
No Hooks.
Returns
Array.
Usage
$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 Report Sales By Product::get chart legend code WC 10.3.3
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( OrderStatus::COMPLETED, OrderStatus::PROCESSING, OrderStatus::ON_HOLD, OrderStatus::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( OrderStatus::COMPLETED, OrderStatus::PROCESSING, OrderStatus::ON_HOLD, OrderStatus::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;
}