prepare_to_printing_export($post_ids, $redirect_to); break; case 'set_status_to_prepare_to_printing': $redirect_to = $this->set_status_to_prepare_to_printing($post_ids, $redirect_to); break; case 'set_status_to_in_printing': $redirect_to = $this->set_status_to_in_printing($post_ids, $redirect_to); break; } return $redirect_to; } private function prepare_to_printing_export($post_ids, $redirect_to) { // Get orders data using the DB Manager $orders_data = Studiou_DB_Manager::get_orders_for_printing($post_ids); // Update order statuses $this->set_status_to_prepare_to_printing($post_ids, $redirect_to); UtilsLog::log('Order statuses set to "to-print" after export.'); UtilsLog::message('Order statuses (' . count($orders_data) . ') set to "to-print" after export.', 'info' ); if (!empty($orders_data)) { $csv_data = $this->generate_csv($orders_data); UtilsLog::log('file prepare_to_printing_export.csv exported'); $this->output_csv($csv_data, 'prepare_to_printing_export.csv'); } return $redirect_to; } private function set_status_to_prepare_to_printing($post_ids, $redirect_to) { // Use the DB Manager to update order statuses Studiou_DB_Manager::set_orders_to_prepare_printing($post_ids); $redirect_to = add_query_arg('bulk_action', 'marked_prepare_to_printing', $redirect_to); return $redirect_to; } private function set_status_to_in_printing($post_ids, $redirect_to) { // Use the DB Manager to update order statuses Studiou_DB_Manager::set_orders_to_in_printing($post_ids); $redirect_to = add_query_arg('bulk_action', 'marked_in_printing', $redirect_to); return $redirect_to; } private function generate_csv($data) { $output = fopen('php://temp', 'w'); fputcsv($output, array_keys((array)$data[0]),','); // Headers foreach ($data as $row) { fputcsv($output, (array)$row, ','); } rewind($output); $csv = stream_get_contents($output); fclose($output); return $csv; } private function output_csv($csv_data, $filename) { header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="' . $filename . '"'); echo $csv_data; exit; } }