WC_Report_Customers::customers_vs_guests()publicWC 1.0

Output customers vs guests chart.

Method of the class: WC_Report_Customers{}

No Hooks.

Return

null. Nothing (null).

Usage

$WC_Report_Customers = new WC_Report_Customers();
$WC_Report_Customers->customers_vs_guests();

WC_Report_Customers::customers_vs_guests() code WC 8.6.1

<?php
public function customers_vs_guests() {

	$customer_order_totals = $this->get_order_report_data(
		array(
			'data'         => array(
				'ID' => array(
					'type'     => 'post_data',
					'function' => 'COUNT',
					'name'     => 'total_orders',
				),
			),
			'where_meta'   => array(
				array(
					'meta_key'   => '_customer_user',
					'meta_value' => '0',
					'operator'   => '>',
				),
			),
			'filter_range' => true,
		)
	);

	$guest_order_totals = $this->get_order_report_data(
		array(
			'data'         => array(
				'ID' => array(
					'type'     => 'post_data',
					'function' => 'COUNT',
					'name'     => 'total_orders',
				),
			),
			'where_meta'   => array(
				array(
					'meta_key'   => '_customer_user',
					'meta_value' => '0',
					'operator'   => '=',
				),
			),
			'filter_range' => true,
		)
	);
	?>
	<div class="chart-container">
		<div class="chart-placeholder customers_vs_guests pie-chart" style="height:200px"></div>
		<ul class="pie-chart-legend">
			<li style="border-color: <?php echo esc_attr( $this->chart_colours['customers'] ); ?>"><?php esc_html_e( 'Customer sales', 'woocommerce' ); ?></li>
			<li style="border-color: <?php echo esc_attr( $this->chart_colours['guests'] ); ?>"><?php esc_html_e( 'Guest sales', 'woocommerce' ); ?></li>
		</ul>
	</div>
	<script type="text/javascript">
		jQuery(function(){
			 jQuery.plot(
				jQuery('.chart-placeholder.customers_vs_guests'),
				[
					{
						label: '<?php esc_html_e( 'Customer orders', 'woocommerce' ); ?>',
						data:  "<?php echo esc_html( $customer_order_totals->total_orders ); ?>",
						color: '<?php echo esc_html( $this->chart_colours['customers'] ); ?>'
					},
					{
						label: '<?php esc_html_e( 'Guest orders', 'woocommerce' ); ?>',
						data:  "<?php echo esc_html( $guest_order_totals->total_orders ); ?>",
						color: '<?php echo esc_html( $this->chart_colours['guests'] ); ?>'
					}
				],
				{
					grid: {
						hoverable: true
					},
					series: {
						pie: {
							show: true,
							radius: 1,
							innerRadius: 0.6,
							label: {
								show: false
							}
						},
						enable_tooltip: true,
						append_tooltip: "<?php echo esc_html( ' ' . __( 'orders', 'woocommerce' ) ); ?>",
					},
					legend: {
						show: false
					}
				}
			);

			jQuery('.chart-placeholder.customers_vs_guests').trigger( 'resize' );
		});
	</script>
	<?php
}