Automattic\WooCommerce\Admin\API
Leaderboards::get_categories_leaderboard()
Get the data for the categories leaderboard.
Метод класса: Leaderboards{}
Хуки из метода
Возвращает
null
. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_categories_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_categories_leaderboard() Leaderboards::get categories leaderboard WC 9.4.2
protected function get_categories_leaderboard( $per_page, $after, $before, $persisted_query ) { $categories_data_store = new CategoriesDataStore(); $categories_data = $per_page > 0 ? $categories_data_store->get_data( apply_filters( 'woocommerce_analytics_categories_query_args', array( 'orderby' => 'items_sold', 'order' => 'desc', 'after' => $after, 'before' => $before, 'per_page' => $per_page, 'extended_info' => true, ) ) )->data : array(); $rows = array(); foreach ( $categories_data as $category ) { $url_query = wp_parse_args( array( 'filter' => 'single_category', 'categories' => $category['category_id'], ), $persisted_query ); $category_url = wc_admin_url( '/analytics/categories', $url_query ); $category_name = isset( $category['extended_info'] ) && isset( $category['extended_info']['name'] ) ? $category['extended_info']['name'] : ''; $rows[] = array( array( 'display' => "<a href='{$category_url}'>{$category_name}</a>", 'value' => $category_name, ), array( 'display' => wc_admin_number_format( $category['items_sold'] ), 'value' => $category['items_sold'], 'format' => 'number', ), array( 'display' => wc_price( $category['net_revenue'] ), 'value' => $category['net_revenue'], 'format' => 'currency', ), ); } return array( 'id' => 'categories', 'label' => __( 'Top categories - Items sold', 'woocommerce' ), 'headers' => array( array( 'label' => __( 'Category', 'woocommerce' ), ), array( 'label' => __( 'Items sold', 'woocommerce' ), ), array( 'label' => __( 'Net sales', 'woocommerce' ), ), ), 'rows' => $rows, ); }