/** * Bulk booking requests. * * @param array $post_ids Array of WC_Order ID's */ static function bulk_send_booking($post_ids) { foreach ($post_ids as $post_id) { $order = new Bring_WC_Order_Adapter(new WC_Order($post_id)); if (!$order->has_booking_consignments()) { self::send_booking($order->order); } } }
static function open_pdfs() { add_submenu_page(null, 'Download', 'Download', 'manage_woocommerce', 'bring_labels', function () { if (!isset($_GET['order_ids']) || $_GET['order_ids'] == '') { return; } $current_user = wp_get_current_user(); // ID 0 is a not an user. if ($current_user->ID == 0) { exit; } // Admins and managers can download all orders. $can_download = in_array('manage_woocommerce', $current_user->roles) || in_array('administrator', $current_user->roles); if (!$can_download) { exit; } $order_ids = explode(',', $_GET['order_ids']); $files_to_merge = []; foreach ($order_ids as $order_id) { $order = new Bring_WC_Order_Adapter(new WC_Order($order_id)); if (!$order->has_booking_consignments()) { continue; } $consignments = $order->get_booking_consignments(); foreach ($consignments as $consignment) { $confirmation = $consignment->confirmation; $consignment_number = $confirmation->consignmentNumber; $file_path = Bring_Booking_Labels::get_file_path($order->order->id, $consignment_number); if (file_exists($file_path)) { $files_to_merge[] = Bring_Booking_Labels::get_file_path($order->order->id, $consignment_number); } } } include_once FRAKTGUIDEN_PLUGIN_PATH . '/vendor/myokyawhtun/pdfmerger/PDFMerger.php'; $merger = new PDFMerger(); foreach ($files_to_merge as $file) { $merger->addPDF($file); } $merge_result_file = Bring_Booking_Labels::get_local_dir() . '/labels-merged.pdf'; $merger->merge('file', $merge_result_file); header("Content-Length: " . filesize($merge_result_file)); header("Content-type: application/pdf"); header("Content-disposition: inline; filename=" . basename($merge_result_file)); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); // Workaround for Chrome's inline pdf viewer ob_clean(); flush(); readfile($merge_result_file); exit; }); }