WC_Report_Coupon_Usage::get_chart_legend()publicWC 1.0

Get the legend for the main chart sidebar.

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

Хуков нет.

Возвращает

Массив.

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

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

Код WC_Report_Coupon_Usage::get_chart_legend() WC 8.7.0

public function get_chart_legend() {
	$legend = array();

	$total_discount_query = array(
		'data'         => array(
			'discount_amount' => array(
				'type'            => 'order_item_meta',
				'order_item_type' => 'coupon',
				'function'        => 'SUM',
				'name'            => 'discount_amount',
			),
		),
		'where'        => array(
			array(
				'key'      => 'order_item_type',
				'value'    => 'coupon',
				'operator' => '=',
			),
		),
		'query_type'   => 'get_var',
		'filter_range' => true,
		'order_types'  => wc_get_order_types( 'order-count' ),
	);

	$total_coupons_query = array(
		'data'         => array(
			'order_item_id' => array(
				'type'            => 'order_item',
				'order_item_type' => 'coupon',
				'function'        => 'COUNT',
				'name'            => 'order_coupon_count',
			),
		),
		'where'        => array(
			array(
				'key'      => 'order_item_type',
				'value'    => 'coupon',
				'operator' => '=',
			),
		),
		'query_type'   => 'get_var',
		'filter_range' => true,
		'order_types'  => wc_get_order_types( 'order-count' ),
	);

	if ( ! empty( $this->coupon_codes ) ) {
		$coupon_code_query = array(
			'type'     => 'order_item',
			'key'      => 'order_item_name',
			'value'    => $this->coupon_codes,
			'operator' => 'IN',
		);

		$total_discount_query['where'][] = $coupon_code_query;
		$total_coupons_query['where'][]  = $coupon_code_query;
	}

	$total_discount = $this->get_order_report_data( $total_discount_query );
	$total_coupons  = absint( $this->get_order_report_data( $total_coupons_query ) );

	$legend[] = array(
		/* translators: %s: discount amount */
		'title'            => sprintf( __( '%s discounts in total', 'woocommerce' ), '<strong>' . wc_price( $total_discount ) . '</strong>' ),
		'color'            => $this->chart_colours['discount_amount'],
		'highlight_series' => 1,
	);

	$legend[] = array(
		/* translators: %s: coupons amount */
		'title'            => sprintf( __( '%s coupons used in total', 'woocommerce' ), '<strong>' . $total_coupons . '</strong>' ),
		'color'            => $this->chart_colours['coupon_count'],
		'highlight_series' => 0,
	);

	return $legend;
}