diff --git a/src/Order/Base.php b/src/Order/Base.php index 7e167f95..d51c39eb 100644 --- a/src/Order/Base.php +++ b/src/Order/Base.php @@ -537,14 +537,7 @@ function ( $barc ) { $barcodes ); - $saved_data['labels'] = array_map( - function ( $label ) { - unset( $label['merged_files'] ); - - return $label; - }, - $labels - ); + $saved_data['labels'] = $labels; if ( $this->settings->is_auto_complete_order_enabled() ) { // Updating the order status to completed. @@ -711,7 +704,8 @@ public function put_label_content( $response, $order, $parent_barcode, $parent_l $label_extension = ! empty( $label_contents['OutputType'] ) ? sanitize_title( $label_contents['OutputType'] ) : 'pdf'; $barcode = $response[ $type ][ $shipment_idx ][ $content_type['barcode_key'] ]; $barcode = is_array( $barcode ) ? array_shift( $barcode ) : $barcode; - $filename = Utils::generate_label_name( $order->get_id(), $label_type, $barcode, 'A6', $label_extension ); + $label_format = $this->settings->get_label_format(); + $filename = Utils::generate_label_name( $order->get_id(), $label_type, $barcode, $label_format, $label_extension ); $filepath = trailingslashit( POSTNL_UPLOADS_DIR ) . $filename; if ( wp_mkdir_p( POSTNL_UPLOADS_DIR ) && ! file_exists( $filepath ) ) { @@ -1277,6 +1271,12 @@ public function delete_label( $saved_data ) { return false; } + if ( isset( $saved_data['labels']['label']['merged_files'] ) ) { + foreach ( $saved_data['labels']['label']['merged_files'] as $label_path ) { + unlink( $label_path ); + } + } + return unlink( $saved_data['labels']['label']['filepath'] ); } @@ -1419,29 +1419,6 @@ protected function get_tracking_link( $order_id ) { return sprintf( '%2$s', esc_url( $tracking_url ), $saved_data['labels']['label']['barcode'] ); } - /** - * Delete label files from label info. - * - * @param Array $labels List of label info. - */ - public function delete_label_files( $labels ) { - if ( empty( $labels ) ) { - return; - } - - foreach ( $labels as $label_type => $label_info ) { - if ( empty( $label_info['merged_files'] ) || empty( $label_info['filepath'] ) ) { - continue; - } - - foreach ( $label_info['merged_files'] as $path ) { - if ( file_exists( $path ) && $path !== $label_info['filepath'] ) { - unlink( $path ); - } - } - } - } - /** * Check if the order have the label data. * diff --git a/src/Order/Bulk.php b/src/Order/Bulk.php index b2c17076..3d82efd9 100644 --- a/src/Order/Bulk.php +++ b/src/Order/Bulk.php @@ -229,10 +229,6 @@ public function merge_bulk_labels( $gen_labels ) { $merged_info = $this->merge_labels( $label_paths, $filename, $start_position ); - foreach ( $gen_labels as $labels ) { - $this->delete_label_files( $labels ); - } - if ( file_exists( $merged_info ['filepath'] ) ) { // We're saving the bulk file path temporarily and access it later during the download process. // This information expires in 3 minutes (180 seconds), just enough for the user to see the diff --git a/src/Order/Single.php b/src/Order/Single.php index ea91188f..12669ef1 100644 --- a/src/Order/Single.php +++ b/src/Order/Single.php @@ -460,8 +460,6 @@ public function save_meta_box_ajax() { $labels = $result['labels']; $tracking_note = $this->get_tracking_note( $order_id ); - $this->delete_label_files( $labels ); - if ( ! empty( $tracking_note ) ) { $return_data = array_merge( $result['saved_data'],