WC_Admin_Report::sales_sparkline()publicWC 1.0

Prepares the markup for a sparkline to show sales in the last X days.

Method of the class: WC_Admin_Report{}

No Hooks.

Return

String.

Usage

$WC_Admin_Report = new WC_Admin_Report();
$WC_Admin_Report->sales_sparkline( $id, $days, $type );
$id(int)
ID of the product to show. Blank to get all orders.
Default: ''
$days(int)
Days of stats to get.
Default: 7 days
$type(string)
Type of sparkline to get.
Default: 'sales'

WC_Admin_Report::sales_sparkline() code WC 9.8.1

public function sales_sparkline( $id = '', $days = 7, $type = 'sales' ) {
	$sparkline = $this->get_sales_sparkline( $id, $days, $type );
	$total     = $sparkline['total'];

	if ( 'sales' === $type ) {
		/* translators: 1: total income 2: days */
		$tooltip = sprintf( __( 'Sold %1$s worth in the last %2$d days', 'woocommerce' ), wp_strip_all_tags( wc_price( $total ) ), $days );
	} else {
		/* translators: 1: total items sold 2: days */
		$tooltip = sprintf( _n( 'Sold %1$d item in the last %2$d days', 'Sold %1$d items in the last %2$d days', $total, 'woocommerce' ), $total, $days );
	}

	$sparkline_data = $sparkline['data'];

	return '<span class="wc_sparkline ' . ( ( 'sales' === $type ) ? 'lines' : 'bars' ) . ' tips" data-color="#777" data-tip="' . esc_attr( $tooltip ) . '" data-barwidth="' . 60 * 60 * 16 * 1000 . '" data-sparkline="' . wc_esc_json( wp_json_encode( $sparkline_data ) ) . '"></span>';
}