$period, 'start_date' => $start_date, 'end_date' => $end_date, ); // Resolve Dates if ( class_exists( 'ANFOWO_Date_Resolver' ) ) { $dates = ANFOWO_Date_Resolver::resolve( $params ); } else { $dates = array( 'start' => gmdate( 'Y-m-d', strtotime( '-30 days' ) ), 'end' => gmdate( 'Y-m-d' ) ); } // Capture View output ob_start(); $chart_data = $this->render_view( $tab, $dates ); $html = ob_get_clean(); $response = array( 'html' => $html, 'chart' => $chart_data, ); wp_send_json_success( $response ); } public function render_view( $tab, $dates ) { $data = array(); $chart_data = array(); switch ( $tab ) { case 'overview': if ( class_exists( 'ANFOWO_Product_Query' ) ) { $overview_data = ANFOWO_Product_Query::get_overview( $dates ); $data['summary'] = ANFOWO_Product_Query::get_summary( $dates ); $chart_data = array( 'labels' => $overview_data['chart']['labels'], 'data' => $overview_data['chart']['revenue'] ); } include ANFOWO_PLUGIN_DIR . 'admin/views/overview.php'; break; case 'products': if ( class_exists( 'ANFOWO_Product_Query' ) ) { $data['products'] = ANFOWO_Product_Query::get_report( $dates ); $chart_data = array( 'labels' => $data['products']['chart']['labels'], 'data' => $data['products']['chart']['quantity'], 'is_quantity' => true, 'label' => __( 'Quantity', '360-analytics-for-woocommerce' ), ); } include ANFOWO_PLUGIN_DIR . 'admin/views/product-report.php'; break; case 'categories': if ( class_exists( 'ANFOWO_Category_Query' ) ) { $data['categories'] = ANFOWO_Category_Query::get_report( $dates ); $chart_data = array( 'labels' => $data['categories']['chart']['labels'], 'data' => $data['categories']['chart']['quantity'], 'is_quantity' => true, 'label' => __( 'Quantity', '360-analytics-for-woocommerce' ), ); } include ANFOWO_PLUGIN_DIR . 'admin/views/category-report.php'; break; case 'taxonomies': // phpcs:ignore WordPress.Security.NonceVerification.Missing $taxonomy_type = isset( $_POST['taxonomy'] ) ? sanitize_text_field( wp_unslash( $_POST['taxonomy'] ) ) : 'all'; if ( class_exists( 'ANFOWO_Taxonomy_Query' ) ) { $data['taxonomies'] = ANFOWO_Taxonomy_Query::get_report( $dates, $taxonomy_type ); $data['taxonomies']['current_taxonomy'] = $taxonomy_type; $chart_data = array( 'labels' => $data['taxonomies']['chart']['labels'], 'data' => $data['taxonomies']['chart']['quantity'], 'is_quantity' => true, 'label' => __( 'Quantity', '360-analytics-for-woocommerce' ), ); } include ANFOWO_PLUGIN_DIR . 'admin/views/taxonomy-report.php'; break; case 'taxes': if ( class_exists( 'ANFOWO_Tax_Query' ) ) { $data['taxes'] = ANFOWO_Tax_Query::get_report( $dates ); $chart_data = array(); // Taxes might not need a chart } include ANFOWO_PLUGIN_DIR . 'admin/views/tax-report.php'; break; case 'orders': if ( class_exists( 'ANFOWO_Order_Query' ) ) { $data['orders'] = ANFOWO_Order_Query::get_report( $dates ); $chart_data = array(); } include ANFOWO_PLUGIN_DIR . 'admin/views/orders-report.php'; break; case 'customers': if ( class_exists( 'ANFOWO_Customer_Query' ) ) { $data['customers'] = ANFOWO_Customer_Query::get_report( $dates ); $chart_data = array( 'labels' => $data['customers']['chart']['labels'], 'data' => $data['customers']['chart']['quantity'], 'is_quantity' => true, 'label' => __( 'Quantity', '360-analytics-for-woocommerce' ), ); } include ANFOWO_PLUGIN_DIR . 'admin/views/customer-report.php'; break; } return $chart_data; } public function get_chart_data( $tab, $dates ) { // Deprecated: Now returned directly by render_view return array(); } }