WC_Admin_Dashboard::get_wc_admin_performance_data()
Gets the sales performance data from the new WooAdmin store.
Метод класса: WC_Admin_Dashboard{}
Хуков нет.
Возвращает
stdClass|WP_Error|WP_REST_Response
.
Использование
// private - только в коде основоного (родительского) класса $result = $this->get_wc_admin_performance_data();
Код WC_Admin_Dashboard::get_wc_admin_performance_data() WC Admin Dashboard::get wc admin performance data WC 9.3.3
private function get_wc_admin_performance_data() { $request = new \WP_REST_Request( 'GET', '/wc-analytics/reports/performance-indicators' ); $start_date = gmdate( 'Y-m-01 00:00:00', current_time( 'timestamp' ) ); $end_date = gmdate( 'Y-m-d 23:59:59', current_time( 'timestamp' ) ); $request->set_query_params( array( 'before' => $end_date, 'after' => $start_date, 'stats' => 'revenue/total_sales,revenue/net_revenue,orders/orders_count,products/items_sold,variations/items_sold', ) ); $response = rest_do_request( $request ); if ( is_wp_error( $response ) ) { return $response; } if ( 200 !== $response->get_status() ) { return new \WP_Error( 'woocommerce_analytics_performance_indicators_result_failed', __( 'Sorry, fetching performance indicators failed.', 'woocommerce' ) ); } $report_keys = array( 'net_revenue' => 'net_sales', ); $performance_data = new stdClass(); foreach ( $response->get_data() as $indicator ) { if ( isset( $indicator['chart'] ) && isset( $indicator['value'] ) ) { $key = isset( $report_keys[ $indicator['chart'] ] ) ? $report_keys[ $indicator['chart'] ] : $indicator['chart']; $performance_data->$key = $indicator['value']; } } return $performance_data; }