Просмотр исходного кода

add instructions, readme, lates changes

Dalibor Votruba 1 год назад
Родитель
Сommit
2e14bfc316

+ 36 - 0
studiou-wc-ord-print-statuses/instructions.txt

@@ -0,0 +1,36 @@
+Write WordPress plugin called "studiou-wc-ord-print-statuses" in PHP, that extends WooCommerce plugin.
+Plugin will have following features:
+
+1. Extends Order status aligned after status wc-processing:
+	wc-to-print - Prepare to Printing
+	wc-in-print - In Printing
+2. Extends Order fields (add new fields):
+	to-print-date (DateTime) - Prepare To Print Date
+	in-print-date (DateTime) - In Print Date
+	external-ref-ord-no (varchar) - External Order Number
+	external-ref-ord-delivered (DateTime) - External Order Delivered
+	
+3. In screen WooCommerce/Orders in combo near "Search Order" button there will be allow to find orders by field external-ref-ord-no
+	
+4. In screen WooCommerce/Orders extends (add new options) combo-box Bulk Actions for actions:
+	Prepare to Printing Export
+		- export all selected orders by using custom sql "SELECT * FROM `vsu_orders_car_prod_qty_img`" to .csv file
+		- set all selected order statuses to wc-to-print and set order field to-print-date to current date.
+	Set Status to Prepare to Printing
+		- set all selected order statuses to wc-to-print and set order field to-print-date to current date.
+	Set Status to In Printing
+		- set all selected order statuses to wc-in-print and set order field in-print-date to current date.
+
+5. In screen WooCommerce/Orders overview grid add columns (at the end) for new fields to-print-date, in-print-date, external-ref-ord-no
+		
+6. In screen WooCommerce/Orders add button "Import InPrint protocol" that will do (after press):
+	- Import .csv file from local disk.
+	- Import file will have following columns: "Order No", "ExternalOrder", "ExternalOrderDate"
+	- Distinct values from import file by column "Order No"
+	- Update all Orders in database, defined by column "Order" No and set order status to wc-in-print and set field in-print-date to current date.
+
+7. In screen WooCommerce/Orders add button "Import Delivered protocol" that will do (after press):
+	- Import .csv file from local disk.
+	- Import file will have following columns: "Order No"
+	- Distinct values from import file by column "Order No"
+	- Update all Orders in database, defined by column "Order" No and set order status to wc-completed and set field external-ref-ord-delivered to current date.

+ 92 - 0
studiou-wc-ord-print-statuses/readme.md

@@ -0,0 +1,92 @@
+# QDR - Studiou WC Order Print Statuses
+
+## Description
+
+QDR - Studiou WC Order Print Statuses is a WordPress plugin that extends WooCommerce functionality to manage print orders sent to third-party providers. It adds custom order statuses, bulk actions, and status change timestamps specific to the printing process.
+
+## Features
+
+- Custom order statuses: "Prepare to Printing" and "In Printing"
+- Bulk actions for managing print orders
+- Custom order fields for tracking print-related information
+- Custom columns in the orders list for quick view of print statuses
+- Import functionality for InPrint and Delivered protocols
+- Search orders by external reference order number
+
+## Installation
+
+1. Upload the `studiou-wc-ord-print-statuses` folder to the `/wp-content/plugins/` directory
+2. Activate the plugin through the 'Plugins' menu in WordPress
+3. Ensure WooCommerce is installed and activated
+
+## Usage
+
+### Custom Order Statuses
+
+The plugin adds two new order statuses:
+
+- Prepare to Printing
+- In Printing
+
+These statuses appear in the order status dropdown and can be used to track the progress of print orders.
+
+### Custom Order Fields
+
+In the order edit page, you'll find a new section called "Print Information" with the following fields:
+
+- Prepare To Print Date
+- In Print Date
+- External Order Number
+- External Order Delivered
+
+### Bulk Actions
+
+New bulk actions are available in the orders list:
+
+- Prepare to Printing Export: Exports selected orders and changes their status to "Prepare to Printing"
+- Set Status to Prepare to Printing
+- Set Status to In Printing
+
+### Custom Columns
+
+The orders list now includes new columns:
+
+- To Print Date
+- In Print Date
+- External Order Number
+
+### Import Functionality
+
+Two import buttons are added to the orders page:
+
+- Import InPrint Protocol: Updates order status to "In Printing" and sets related metadata
+- Import Delivered Protocol: Updates order status to "Completed" and sets delivery date
+
+## Requirements
+
+- WordPress 5.0 or higher
+- WooCommerce 3.0 or higher
+
+## Support
+
+For support, please contact the plugin author at https://www.quadarax.com
+
+## License
+
+This plugin is licensed under the GPL v2 or later.
+
+```
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+```

+ 360 - 108
studiou-wc-ord-print-statuses/studiou-wc-ord-print-statuses.php

@@ -9,58 +9,73 @@
  * License: GPL2
  * License: GPL2
  */
  */
 
 
-// Exit if accessed directly
-if (!defined('ABSPATH')) {
-    exit;
-}
+defined('ABSPATH') or die('Direct access not allowed!');
+
+/**
+ * Main plugin class
+ */
+class Studiou_WC_Ord_Print_Statuses {
 
 
-class Studiou_WC_Order_Print_Statuses {
     /**
     /**
-     * Constructor: Sets up the necessary action and filter hooks
+     * Constructor
      */
      */
     public function __construct() {
     public function __construct() {
-        // Hook for registering custom order status
-        add_action('init', array($this, 'register_custom_order_status'));
-
-        // Filter to add custom status to WooCommerce order statuses list
-        add_filter('wc_order_statuses', array($this, 'add_to_print_order_status_to_list'));
+        add_action('plugins_loaded', array($this, 'init'));
+    }
 
 
-        // Filter to add custom status to WooCommerce order statuses list
-        add_filter('wc_order_statuses', array($this, 'add_in_print_order_status_to_list'));
+    /**
+     * Initialize the plugin
+     */
+    public function init() {
+        // Check if WooCommerce is active
+        if (!class_exists('WooCommerce')) {
+            add_action('admin_notices', array($this, 'woocommerce_missing_notice'));
+            return;
+        }
 
 
-        // Filter to add custom status to bulk actions dropdown
-        add_filter('bulk_actions-edit-shop_order', array($this, 'add_to_print_order_status_to_bulk_actions'));
-        
-        // Filter to add custom status to bulk actions dropdown
-        add_filter('bulk_actions-edit-shop_order', array($this, 'add_in_print_order_status_to_bulk_actions'));
+        // Initialize plugin features
+        $this->add_custom_order_statuses();
+        $this->add_custom_order_fields();
+        $this->modify_order_search();
+        $this->add_bulk_actions();
+        $this->add_custom_columns();
+        $this->add_import_buttons();
+    }
 
 
-        // Filter to handle the custom bulk action
-        add_filter('handle_bulk_actions-edit-shop_order', array($this, 'handle_custom_order_status_bulk_action'), 10, 3);
-        
-        // Action to add timestamp when order status changes
-        add_action('woocommerce_order_status_changed', array($this, 'add_status_change_timestamp'), 10, 4);
-        
-        // Filter to add custom column to orders table
-        add_filter('manage_edit-shop_order_columns', array($this, 'add_order_status_changed_column'));
+    /**
+     * Display a notice if WooCommerce is not active
+     */
+    public function woocommerce_missing_notice() {
+        ?>
+        <div class="error">
+            <p><?php _e('Studiou WC Order Print Statuses requires WooCommerce to be installed and active.', 'studiou-wc-ord-print-statuses'); ?></p>
+        </div>
+        <?php
+    }
 
 
-        // Action to populate the custom column
-        add_action('manage_shop_order_posts_custom_column', array($this, 'populate_order_status_changed_column'), 10, 2);
+    /**
+     * Add custom order statuses
+     */
+    private function add_custom_order_statuses() {
+        add_action('init', array($this, 'register_custom_order_statuses'));
+        add_filter('wc_order_statuses', array($this, 'add_custom_order_statuses_to_list'));
     }
     }
 
 
-     /**
-     * Registers the custom order status with WordPress
+    /**
+     * Register custom order statuses
      */
      */
-    public function register_custom_order_status() {
+    public function register_custom_order_statuses() {
         register_post_status('wc-to-print', array(
         register_post_status('wc-to-print', array(
-            'label' => 'Prepare to Printing',
+            'label' => _x('Prepare to Printing', 'Order status', 'studiou-wc-ord-print-statuses'),
             'public' => true,
             'public' => true,
             'exclude_from_search' => false,
             'exclude_from_search' => false,
             'show_in_admin_all_list' => true,
             'show_in_admin_all_list' => true,
             'show_in_admin_status_list' => true,
             'show_in_admin_status_list' => true,
             'label_count' => _n_noop('Prepare to Printing <span class="count">(%s)</span>', 'Prepare to Printing <span class="count">(%s)</span>')
             'label_count' => _n_noop('Prepare to Printing <span class="count">(%s)</span>', 'Prepare to Printing <span class="count">(%s)</span>')
         ));
         ));
+
         register_post_status('wc-in-print', array(
         register_post_status('wc-in-print', array(
-            'label' => 'In Printing',
+            'label' => _x('In Printing', 'Order status', 'studiou-wc-ord-print-statuses'),
             'public' => true,
             'public' => true,
             'exclude_from_search' => false,
             'exclude_from_search' => false,
             'show_in_admin_all_list' => true,
             'show_in_admin_all_list' => true,
@@ -70,19 +85,17 @@ class Studiou_WC_Order_Print_Statuses {
     }
     }
 
 
     /**
     /**
-     * Adds the wc-to-print order status to the list of WooCommerce order statuses
-     * 
-     * @param array $order_statuses Existing order statuses
-     * @return array Modified order statuses
+     * Add custom order statuses to the list of WooCommerce order statuses
      */
      */
-    public function add_to_print_order_status_to_list($order_statuses) {
+    public function add_custom_order_statuses_to_list($order_statuses) {
         $new_order_statuses = array();
         $new_order_statuses = array();
 
 
-        // Add the custom status after the "Processing" status
         foreach ($order_statuses as $key => $status) {
         foreach ($order_statuses as $key => $status) {
             $new_order_statuses[$key] = $status;
             $new_order_statuses[$key] = $status;
+
             if ($key === 'wc-processing') {
             if ($key === 'wc-processing') {
-                $new_order_statuses['wc-to-print'] = 'Prepare to Printing';
+                $new_order_statuses['wc-to-print'] = _x('Prepare to Printing', 'Order status', 'studiou-wc-ord-print-statuses');
+                $new_order_statuses['wc-in-print'] = _x('In Printing', 'Order status', 'studiou-wc-ord-print-statuses');
             }
             }
         }
         }
 
 
@@ -90,121 +103,360 @@ class Studiou_WC_Order_Print_Statuses {
     }
     }
 
 
     /**
     /**
-     * Adds the wc-in-print order status to the list of WooCommerce order statuses
-     * 
-     * @param array $order_statuses Existing order statuses
-     * @return array Modified order statuses
+     * Add custom order fields
      */
      */
-    public function add_in_print_order_status_to_list($order_statuses) {
-        $new_order_statuses = array();
+    private function add_custom_order_fields() {
+        add_action('woocommerce_admin_order_data_after_order_details', array($this, 'display_custom_order_fields'));
+        add_action('woocommerce_process_shop_order_meta', array($this, 'save_custom_order_fields'));
+    }
 
 
-        // Add the custom status after the "Processing" status
-        foreach ($order_statuses as $key => $status) {
-            $new_order_statuses[$key] = $status;
-            if ($key === 'wc-to-print') {
-                $new_order_statuses['wc-in-print'] = 'In Printing';
-            }
+    /**
+     * Display custom order fields in the order edit page
+     */
+    public function display_custom_order_fields($order) {
+        ?>
+        <div class="order_data_column">
+            <h4><?php _e('Print Information', 'studiou-wc-ord-print-statuses'); ?></h4>
+            <p>
+                <label for="to_print_date"><?php _e('Prepare To Print Date:', 'studiou-wc-ord-print-statuses'); ?></label>
+                <input type="text" class="date-picker" name="to_print_date" id="to_print_date" value="<?php echo esc_attr($order->get_meta('to_print_date')); ?>" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])">
+            </p>
+            <p>
+                <label for="in_print_date"><?php _e('In Print Date:', 'studiou-wc-ord-print-statuses'); ?></label>
+                <input type="text" class="date-picker" name="in_print_date" id="in_print_date" value="<?php echo esc_attr($order->get_meta('in_print_date')); ?>" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])">
+            </p>
+            <p>
+                <label for="external_ref_ord_no"><?php _e('External Order Number:', 'studiou-wc-ord-print-statuses'); ?></label>
+                <input type="text" name="external_ref_ord_no" id="external_ref_ord_no" value="<?php echo esc_attr($order->get_meta('external_ref_ord_no')); ?>">
+            </p>
+            <p>
+                <label for="external_ref_ord_delivered"><?php _e('External Order Delivered:', 'studiou-wc-ord-print-statuses'); ?></label>
+                <input type="text" class="date-picker" name="external_ref_ord_delivered" id="external_ref_ord_delivered" value="<?php echo esc_attr($order->get_meta('external_ref_ord_delivered')); ?>" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])">
+            </p>
+        </div>
+        <?php
+    }
+
+    /**
+     * Save custom order fields
+     */
+    public function save_custom_order_fields($order_id) {
+        $order = wc_get_order($order_id);
+
+        if (isset($_POST['to_print_date'])) {
+            $order->update_meta_data('to_print_date', sanitize_text_field($_POST['to_print_date']));
+        }
+        if (isset($_POST['in_print_date'])) {
+            $order->update_meta_data('in_print_date', sanitize_text_field($_POST['in_print_date']));
+        }
+        if (isset($_POST['external_ref_ord_no'])) {
+            $order->update_meta_data('external_ref_ord_no', sanitize_text_field($_POST['external_ref_ord_no']));
+        }
+        if (isset($_POST['external_ref_ord_delivered'])) {
+            $order->update_meta_data('external_ref_ord_delivered', sanitize_text_field($_POST['external_ref_ord_delivered']));
         }
         }
 
 
-        return $new_order_statuses;
+        $order->save();
     }
     }
 
 
     /**
     /**
-     * Adds the wc-to-print order status to the bulk actions dropdown
-     * 
-     * @param array $bulk_actions Existing bulk actions
-     * @return array Modified bulk actions
+     * Modify order search to include external reference order number
      */
      */
-    public function add_to_print_order_status_to_bulk_actions($bulk_actions) {
-        $bulk_actions['mark_to_print'] = 'Change status to Prepare to Printing';
-        return $bulk_actions;
+    private function modify_order_search() {
+        add_filter('woocommerce_shop_order_search_fields', array($this, 'add_external_ref_ord_no_to_search'));
+    }
+
+    /**
+     * Add external reference order number to search fields
+     */
+    public function add_external_ref_ord_no_to_search($search_fields) {
+        $search_fields[] = 'external_ref_ord_no';
+        return $search_fields;
     }
     }
 
 
     /**
     /**
-     * Adds the wc-in-print order status to the bulk actions dropdown
-     * 
-     * @param array $bulk_actions Existing bulk actions
-     * @return array Modified bulk actions
+     * Add bulk actions to the orders list
      */
      */
-    public function add_in_print_order_status_to_bulk_actions($bulk_actions) {
-        $bulk_actions['mark_in_print'] = 'Change status to In Printing';
+    private function add_bulk_actions() {
+        add_filter('bulk_actions-edit-shop_order', array($this, 'register_bulk_actions'));
+        add_filter('handle_bulk_actions-edit-shop_order', array($this, 'handle_bulk_actions'), 10, 3);
+    }
+
+    /**
+     * Register custom bulk actions
+     */
+    public function register_bulk_actions($bulk_actions) {
+        $bulk_actions['prepare_to_printing_export'] = __('Prepare to Printing Export', 'studiou-wc-ord-print-statuses');
+        $bulk_actions['set_status_to_prepare_to_printing'] = __('Set Status to Prepare to Printing', 'studiou-wc-ord-print-statuses');
+        $bulk_actions['set_status_to_in_printing'] = __('Set Status to In Printing', 'studiou-wc-ord-print-statuses');
         return $bulk_actions;
         return $bulk_actions;
     }
     }
 
 
-ends here
+    /**
+     * Handle custom bulk actions
+     */
+    public function handle_bulk_actions($redirect_to, $action, $post_ids) {
+        if ($action === 'prepare_to_printing_export') {
+            $this->prepare_to_printing_export($post_ids);
+        } elseif ($action === 'set_status_to_prepare_to_printing') {
+            $this->set_status_to_prepare_to_printing($post_ids);
+        } elseif ($action === 'set_status_to_in_printing') {
+            $this->set_status_to_in_printing($post_ids);
+        }
 
 
+        return $redirect_to;
+    }
 
 
     /**
     /**
-     * Handles the custom order status bulk action
-     * 
-     * @param string $redirect_to The redirect URL
-     * @param string $action The bulk action being taken
-     * @param array $post_ids The IDs of the affected orders
-     * @return string The modified redirect URL
+     * Handle the "Prepare to Printing Export" bulk action
      */
      */
-    public function handle_custom_order_status_bulk_action($redirect_to, $action, $post_ids) {
-        if ($action !== 'mark_custom-status') {
-            return $redirect_to;
+    private function prepare_to_printing_export($post_ids) {
+        global $wpdb;
+        $results = $wpdb->get_results("SELECT * FROM `vsu_orders_car_prod_qty_img` WHERE order_id IN (" . implode(',', array_map('intval', $post_ids)) . ")");
+        
+        // Generate CSV file
+        $filename = 'prepare_to_printing_export_' . date('Y-m-d_His') . '.csv';
+        header('Content-Type: text/csv');
+        header('Content-Disposition: attachment; filename="' . $filename . '"');
+        
+        $output = fopen('php://output', 'w');
+        fputcsv($output, array_keys((array)$results[0])); // CSV header
+        
+        foreach ($results as $row) {
+            fputcsv($output, (array)$row);
         }
         }
+        
+        fclose($output);
+        
+        // Update order statuses and to-print-date
+        foreach ($post_ids as $post_id) {
+            $order = wc_get_order($post_id);
+            $order->update_status('wc-to-print');
+            $order->update_meta_data('to_print_date', current_time('mysql'));
+            $order->save();
+        }
+        
+        exit();
+    }
 
 
+    /**
+     * Handle the "Set Status to Prepare to Printing" bulk action
+     */
+    private function set_status_to_prepare_to_printing($post_ids) {
         foreach ($post_ids as $post_id) {
         foreach ($post_ids as $post_id) {
             $order = wc_get_order($post_id);
             $order = wc_get_order($post_id);
-            $order->update_status('custom-status', 'Order status changed by bulk edit:', true);
+            $order->update_status('wc-to-print');
+            $order->update_meta_data('to_print_date', current_time('mysql'));
+            $order->save();
         }
         }
+    }
 
 
-        $redirect_to = add_query_arg('bulk_custom_status_orders_count', count($post_ids), $redirect_to);
-        return $redirect_to;
+    /**
+     * Handle the "Set Status to In Printing" bulk action
+     */
+    private function set_status_to_in_printing($post_ids) {
+        foreach ($post_ids as $post_id) {
+            $order = wc_get_order($post_id);
+            $order->update_status('wc-in-print');
+            $order->update_meta_data('in_print_date', current_time('mysql'));
+            $order->save();
+        }
     }
     }
 
 
     /**
     /**
-     * Adds a timestamp meta data when an order status is changed
-     * 
-     * @param int $order_id The ID of the order being changed
-     * @param string $old_status The old status of the order
-     * @param string $new_status The new status of the order
-     * @param WC_Order $order The order object
+     * Add custom columns to the orders list
      */
      */
-    public function add_status_change_timestamp($order_id, $old_status, $new_status, $order) {
-        $timestamp = current_time('mysql');
-        update_post_meta($order_id, '_status_changed_timestamp', $timestamp);
+    private function add_custom_columns() {
+        add_filter('manage_edit-shop_order_columns', array($this, 'add_custom_shop_order_column'), 20);
+        add_action('manage_shop_order_posts_custom_column', array($this, 'add_custom_shop_order_column_content'), 20, 2);
     }
     }
 
 
     /**
     /**
-     * Adds a new column to the orders table for the status change timestamp
-     * 
-     * @param array $columns Existing columns in the orders table
-     * @return array Modified columns
+     * Add custom columns to the orders list table
      */
      */
-    public function add_order_status_changed_column($columns) {
+    public function add_custom_shop_order_column($columns) {
         $new_columns = array();
         $new_columns = array();
 
 
         foreach ($columns as $column_name => $column_info) {
         foreach ($columns as $column_name => $column_info) {
             $new_columns[$column_name] = $column_info;
             $new_columns[$column_name] = $column_info;
-            if ($column_name === 'order_status') {
-                $new_columns['order_status_changed'] = __('Status Changed', 'woocommerce');
+
+            if ('order_total' === $column_name) {
+                $new_columns['to_print_date'] = __('To Print Date', 'studiou-wc-ord-print-statuses');
+                $new_columns['in_print_date'] = __('In Print Date', 'studiou-wc-ord-print-statuses');
+                $new_columns['external_ref_ord_no'] = __('External Order Number', 'studiou-wc-ord-print-statuses');
             }
             }
         }
         }
 
 
         return $new_columns;
         return $new_columns;
     }
     }
+    /**
+     * Add content to custom columns in the orders list table
+     */
+    public function add_custom_shop_order_column_content($column, $post_id) {
+        $order = wc_get_order($post_id);
+
+        switch ($column) {
+            case 'to_print_date':
+                echo esc_html($order->get_meta('to_print_date'));
+                break;
+            case 'in_print_date':
+                echo esc_html($order->get_meta('in_print_date'));
+                break;
+            case 'external_ref_ord_no':
+                echo esc_html($order->get_meta('external_ref_ord_no'));
+                break;
+        }
+    }
+
+
+     /**
+     * Add import buttons to the orders page
+     */
+    private function add_import_buttons() {
+        add_action('woocommerce_order_list_table_restrict_manage_orders', array($this, 'add_import_buttons_to_orders_page'));
+        add_action('admin_post_import_inprint_protocol', array($this, 'handle_import_inprint_protocol'));
+        add_action('admin_post_import_delivered_protocol', array($this, 'handle_import_delivered_protocol'));
+    }
+
+     /**
+     * Add import buttons to the orders page
+     */
+    public function add_import_buttons_to_orders_page() {
+        ?>
+        <div class="alignleft actions">
+            <button type="button" class="button import-inprint-protocol"><?php _e('Import InPrint Protocol', 'studiou-wc-ord-print-statuses'); ?></button>
+            <button type="button" class="button import-delivered-protocol"><?php _e('Import Delivered Protocol', 'studiou-wc-ord-print-statuses'); ?></button>
+        </div>
+        <script>
+            jQuery(function($) {
+                // Move our buttons after the "Add Order" button
+                var $addOrderButton = $('.page-title-action').first();
+                $('.import-inprint-protocol, .import-delivered-protocol').insertAfter($addOrderButton);
+
+                $('.import-inprint-protocol').click(function() {
+                    var fileInput = $('<input type="file" accept=".csv" style="display:none;">');
+                    fileInput.appendTo('body').trigger('click');
+                    fileInput.on('change', function() {
+                        var formData = new FormData();
+                        formData.append('action', 'import_inprint_protocol');
+                        formData.append('file', this.files[0]);
+                        
+                        $.ajax({
+                            url: '<?php echo admin_url('admin-post.php'); ?>',
+                            type: 'POST',
+                            data: formData,
+                            processData: false,
+                            contentType: false,
+                            success: function(response) {
+                                alert('InPrint Protocol import completed successfully.');
+                                location.reload();
+                            },
+                            error: function() {
+                                alert('InPrint Protocol import failed. Please try again.');
+                            }
+                        });
+                    });
+                });
+
+                $('.import-delivered-protocol').click(function() {
+                    var fileInput = $('<input type="file" accept=".csv" style="display:none;">');
+                    fileInput.appendTo('body').trigger('click');
+                    fileInput.on('change', function() {
+                        var formData = new FormData();
+                        formData.append('action', 'import_delivered_protocol');
+                        formData.append('file', this.files[0]);
+                        
+                        $.ajax({
+                            url: '<?php echo admin_url('admin-post.php'); ?>',
+                            type: 'POST',
+                            data: formData,
+                            processData: false,
+                            contentType: false,
+                            success: function(response) {
+                                alert('Delivered Protocol import completed successfully.');
+                                location.reload();
+                            },
+                            error: function() {
+                                alert('Delivered Protocol import failed. Please try again.');
+                            }
+                        });
+                    });
+                });
+            });
+        </script>
+        <?php
+    }
 
 
     /**
     /**
-     * Populates the custom column with the status change timestamp
-     * 
-     * @param string $column The name of the column to populate
-     * @param int $post_id The ID of the order
+     * Handle the import of InPrint protocol
      */
      */
-    public function populate_order_status_changed_column($column, $post_id) {
-        if ($column == 'order_status_changed') {
-            $timestamp = get_post_meta($post_id, '_status_changed_timestamp', true);
-            if ($timestamp) {
-                echo date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($timestamp));
-            } else {
-                echo '—';
+    public function handle_import_inprint_protocol() {
+        if (!isset($_FILES['file']) || $_FILES['file']['error'] !== UPLOAD_ERR_OK) {
+            wp_die('File upload failed.');
+        }
+
+        $file = fopen($_FILES['file']['tmp_name'], 'r');
+        if ($file === false) {
+            wp_die('Failed to open the uploaded file.');
+        }
+
+        // Skip the header row
+        fgetcsv($file);
+
+        while (($data = fgetcsv($file)) !== false) {
+            $order_number = $data[0];
+            $external_order = $data[1];
+            $external_order_date = $data[2];
+
+            $order = wc_get_order($order_number);
+            if ($order) {
+                $order->update_status('wc-in-print');
+                $order->update_meta_data('in_print_date', current_time('mysql'));
+                $order->update_meta_data('external_ref_ord_no', $external_order);
+                $order->save();
             }
             }
         }
         }
+
+        fclose($file);
+
+        wp_redirect(admin_url('edit.php?post_type=shop_order'));
+        exit;
+    }
+
+    /**
+     * Handle the import of Delivered protocol
+     */
+    public function handle_import_delivered_protocol() {
+        if (!isset($_FILES['file']) || $_FILES['file']['error'] !== UPLOAD_ERR_OK) {
+            wp_die('File upload failed.');
+        }
+
+        $file = fopen($_FILES['file']['tmp_name'], 'r');
+        if ($file === false) {
+            wp_die('Failed to open the uploaded file.');
+        }
+
+        // Skip the header row
+        fgetcsv($file);
+
+        while (($data = fgetcsv($file)) !== false) {
+            $order_number = $data[0];
+
+            $order = wc_get_order($order_number);
+            if ($order) {
+                $order->update_status('wc-completed');
+                $order->update_meta_data('external_ref_ord_delivered', current_time('mysql'));
+                $order->save();
+            }
+        }
+
+        fclose($file);
+
+        wp_redirect(admin_url('edit.php?post_type=shop_order'));
+        exit;
     }
     }
 }
 }
 
 
-// Instantiate the plugin class
-new Studiou_WC_Order_Print_Statuses();
+
+// Initialize the plugin
+ new Studiou_WC_Ord_Print_Statuses();