WC_Report_Sales_By_Category::output_report()publicWC 1.0

Output the report.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

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

Код WC_Report_Sales_By_Category::output_report() WC 9.4.2

public function output_report() {

	$ranges = array(
		'year'       => __( 'Year', 'woocommerce' ),
		'last_month' => __( 'Last month', 'woocommerce' ),
		'month'      => __( 'This month', 'woocommerce' ),
		'7day'       => __( 'Last 7 days', 'woocommerce' ),
	);

	$this->chart_colours = array( '#3498db', '#34495e', '#1abc9c', '#2ecc71', '#f1c40f', '#e67e22', '#e74c3c', '#2980b9', '#8e44ad', '#2c3e50', '#16a085', '#27ae60', '#f39c12', '#d35400', '#c0392b' );

	$current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : '7day';

	if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) ) {
		$current_range = '7day';
	}

	$this->check_current_range_nonce( $current_range );
	$this->calculate_current_range( $current_range );

	// Get item sales data.
	if ( ! empty( $this->show_categories ) ) {
		$order_items = $this->get_order_report_data(
			array(
				'data'         => array(
					'_product_id' => array(
						'type'            => 'order_item_meta',
						'order_item_type' => 'line_item',
						'function'        => '',
						'name'            => 'product_id',
					),
					'_line_total' => array(
						'type'            => 'order_item_meta',
						'order_item_type' => 'line_item',
						'function'        => 'SUM',
						'name'            => 'order_item_amount',
					),
					'post_date'   => array(
						'type'     => 'post_data',
						'function' => '',
						'name'     => 'post_date',
					),
				),
				'group_by'     => 'ID, product_id, post_date',
				'query_type'   => 'get_results',
				'filter_range' => true,
			)
		);

		$this->item_sales           = array();
		$this->item_sales_and_times = array();

		if ( is_array( $order_items ) ) {

			foreach ( $order_items as $order_item ) {

				switch ( $this->chart_groupby ) {
					case 'day':
						$time = strtotime( gmdate( 'Ymd', strtotime( $order_item->post_date ) ) ) * 1000;
						break;
					case 'month':
					default:
						$time = strtotime( gmdate( 'Ym', strtotime( $order_item->post_date ) ) . '01' ) * 1000;
						break;
				}

				$this->item_sales_and_times[ $time ][ $order_item->product_id ] = isset( $this->item_sales_and_times[ $time ][ $order_item->product_id ] ) ? $this->item_sales_and_times[ $time ][ $order_item->product_id ] + $order_item->order_item_amount : $order_item->order_item_amount;

				$this->item_sales[ $order_item->product_id ] = isset( $this->item_sales[ $order_item->product_id ] ) ? $this->item_sales[ $order_item->product_id ] + $order_item->order_item_amount : $order_item->order_item_amount;
			}
		}
	}

	include WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php';
}