private static function generate_fraktguiden_options($options) { $is_pro = class_exists('WC_Shipping_Method_Bring_Pro'); self::create_row('pro', $is_pro ? 'yes' : 'no'); foreach ($options as $key => $option) { $val = ''; if (gettype($option) == 'array') { $val .= '<ul>'; foreach ($option as $o) { $val .= '<li>' . $o . '</li>'; } $val .= '</ul>'; } else { $val = $option; } if ($key == 'mybring_api_key') { $val = '*******'; } self::create_row($key, $val); } if ($is_pro) { self::create_row('labels_directory', Bring_Booking_Labels::get_local_dir()); } }
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; }); }