Automattic\WooCommerce\Admin\API
Leaderboards::get_customers_leaderboard()
Get the data for the customers leaderboard.
Метод класса: Leaderboards{}
Хуки из метода
Возвращает
null
. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_customers_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_customers_leaderboard() Leaderboards::get customers leaderboard WC 9.7.1
protected function get_customers_leaderboard( $per_page, $after, $before, $persisted_query ) { $customers_data_store = new CustomersDataStore(); $customers_data = $per_page > 0 ? $customers_data_store->get_data( apply_filters( 'woocommerce_analytics_customers_query_args', array( 'orderby' => 'total_spend', 'order' => 'desc', 'order_after' => $after, 'order_before' => $before, 'per_page' => $per_page, ) ) )->data : array(); $rows = array(); foreach ( $customers_data as $customer ) { $url_query = wp_parse_args( array( 'filter' => 'single_customer', 'customers' => $customer['id'], ), $persisted_query ); $customer_url = wc_admin_url( '/analytics/customers', $url_query ); $rows[] = array( array( 'display' => "<a href='{$customer_url}'>{$customer['name']}</a>", 'value' => $customer['name'], ), array( 'display' => wc_admin_number_format( $customer['orders_count'] ), 'value' => $customer['orders_count'], 'format' => 'number', ), array( 'display' => wc_price( $customer['total_spend'] ), 'value' => $customer['total_spend'], 'format' => 'currency', ), ); } return array( 'id' => 'customers', 'label' => __( 'Top Customers - Total Spend', 'woocommerce' ), 'headers' => array( array( 'label' => __( 'Customer Name', 'woocommerce' ), ), array( 'label' => __( 'Orders', 'woocommerce' ), ), array( 'label' => __( 'Total Spend', 'woocommerce' ), ), ), 'rows' => $rows, ); }