Automattic\WooCommerce\Admin\API

Leaderboards::get_coupons_leaderboard()protectedWC 1.0

Get the data for the coupons leaderboard.

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

Хуки из метода

Возвращает

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

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_coupons_leaderboard( $per_page, $after, $before, $persisted_query );
$per_page(int) (обязательный)
Number of rows.
$after(строка) (обязательный)
Items after date.
$before(строка) (обязательный)
Items before date.
$persisted_query(строка) (обязательный)
URL query string.

Код Leaderboards::get_coupons_leaderboard() WC 9.3.3

protected function get_coupons_leaderboard( $per_page, $after, $before, $persisted_query ) {
	$coupons_data_store = new CouponsDataStore();
	$coupons_data       = $per_page > 0 ? $coupons_data_store->get_data(
		apply_filters(
			'woocommerce_analytics_coupons_query_args',
			array(
				'orderby'       => 'orders_count',
				'order'         => 'desc',
				'after'         => $after,
				'before'        => $before,
				'per_page'      => $per_page,
				'extended_info' => true,
			)
		)
	)->data : array();

	$rows = array();
	foreach ( $coupons_data as $coupon ) {
		$url_query   = wp_parse_args(
			array(
				'filter'  => 'single_coupon',
				'coupons' => $coupon['coupon_id'],
			),
			$persisted_query
		);
		$coupon_url  = wc_admin_url( '/analytics/coupons', $url_query );
		$coupon_code = isset( $coupon['extended_info'] ) && isset( $coupon['extended_info']['code'] ) ? $coupon['extended_info']['code'] : '';
		$rows[]      = array(
			array(
				'display' => "<a href='{$coupon_url}'>{$coupon_code}</a>",
				'value'   => $coupon_code,
			),
			array(
				'display' => wc_admin_number_format( $coupon['orders_count'] ),
				'value'   => $coupon['orders_count'],
				'format'  => 'number',
			),
			array(
				'display' => wc_price( $coupon['amount'] ),
				'value'   => $coupon['amount'],
				'format'  => 'currency',
			),
		);
	}

	return array(
		'id'      => 'coupons',
		'label'   => __( 'Top Coupons - Number of Orders', 'woocommerce' ),
		'headers' => array(
			array(
				'label' => __( 'Coupon code', 'woocommerce' ),
			),
			array(
				'label' => __( 'Orders', 'woocommerce' ),
			),
			array(
				'label' => __( 'Amount discounted', 'woocommerce' ),
			),
		),
		'rows'    => $rows,
	);
}