Prechádzať zdrojové kódy

extract functionality to more classes, some not working due hookings

Dalibor Votruba 1 rok pred
rodič
commit
7eadc3df7e

+ 90 - 0
studiou-wc-ord-print-statuses/includes/class-bulk-actions-manager.php

@@ -0,0 +1,90 @@
+<?php
+// Handles custom bulk actions for orders.
+// visualized
+class Bulk_Actions_Manager {
+    public function __construct() {
+        add_filter('bulk_actions-woocommerce_page_wc-orders', array($this, 'register_bulk_actions'));
+        add_filter('handle_bulk_actions-woocommerce_page_wc-orders', array($this, 'handle_bulk_actions'), 10, 3);
+    }
+
+    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;
+    }
+
+    public function handle_bulk_actions($redirect_to, $action, $post_ids) {
+        switch ($action) {
+            case 'prepare_to_printing_export':
+                $redirect_to = $this->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) {
+        global $wpdb;
+        $orders_data = $wpdb->get_results("SELECT * FROM `vsu_orders_car_prod_qty_img` WHERE post_id IN (" . implode(',', array_map('intval', $post_ids)) . ")");
+
+        if (!empty($orders_data)) {
+            $csv_data = $this->generate_csv($orders_data);
+            $this->output_csv($csv_data, 'prepare_to_printing_export.csv');
+        }
+
+        $this->set_status_to_prepare_to_printing($post_ids, $redirect_to);
+        return $redirect_to;
+    }
+
+    private function set_status_to_prepare_to_printing($post_ids, $redirect_to) {
+        foreach ($post_ids as $post_id) {
+            $order = wc_get_order($post_id);
+            if ($order) {
+                $order->update_status('to-print');
+                update_post_meta($post_id, 'to-print-date', current_time('mysql'));
+            }
+        }
+        $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) {
+        foreach ($post_ids as $post_id) {
+            $order = wc_get_order($post_id);
+            if ($order) {
+                $order->update_status('in-print');
+                update_post_meta($post_id, 'in-print-date', current_time('mysql'));
+            }
+        }
+        $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;
+    }
+}

+ 49 - 0
studiou-wc-ord-print-statuses/includes/class-custom-columns-manager.php

@@ -0,0 +1,49 @@
+<?php
+//Manages custom columns in the order list.
+// visualized
+
+class Custom_Columns_Manager {
+    public function __construct() {
+        //add_filter('manage_edit-shop_order_columns', array($this, 'add_custom_shop_order_column'));
+        add_filter('manage_woocommerce_page_wc-orders_columns', array($this, 'add_custom_shop_order_column'));
+        //add_filter('manage_woocommerce_page_wc-orders_custom_column', array($this, 'add_custom_shop_order_column'));
+        //add_action('manage_shop_order_posts_custom_column', array($this, 'add_custom_shop_order_column_content'), 10, 2);
+        add_action('manage_woocommerce_page_wc-orders_custom_column', array($this, 'add_custom_shop_order_column_content'), 10, 2);
+    }
+
+    public function add_custom_shop_order_column($columns) {
+        $new_columns = array();
+
+        foreach ($columns as $column_name => $column_info) {
+            $new_columns[$column_name] = $column_info;
+
+            if ($column_name === 'order_total') {
+                $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_order_number'] = __('External Order Number', 'studiou-wc-ord-print-statuses');
+            }
+        }
+
+        return $new_columns;
+    }
+
+    public function add_custom_shop_order_column_content($column, $post_id) {
+        $order = wc_get_order($post_id);
+
+        switch ($column) {
+            case 'to_print_date':
+                $to_print_date = $order->get_meta('to_print_date');
+                echo $to_print_date ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($to_print_date)) : '—';
+                break;
+
+            case 'in_print_date':
+                $in_print_date = $order->get_meta('in_print_date');
+                echo $in_print_date ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($in_print_date)) : '—';
+                break;
+
+            case 'external_order_number':
+                echo $order->get_meta('external_ref_ord_no') ?: '—';
+                break;
+        }
+    }
+}

+ 160 - 0
studiou-wc-ord-print-statuses/includes/class-import-manager.php

@@ -0,0 +1,160 @@
+<?php
+
+//  Handles import functionality for InPrint and Delivered protocols.
+// visualized
+class Import_Manager {
+    public function __construct() {
+        add_action('admin_menu', array($this, 'add_import_submenu'));
+        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'));
+    }
+
+    public function add_import_submenu() {
+        add_submenu_page(
+            'woocommerce',
+            __('Import Protocols', 'studiou-wc-ord-print-statuses'),
+            __('Import Protocols', 'studiou-wc-ord-print-statuses'),
+            'manage_woocommerce',
+            'studiou-import-protocols',
+            array($this, 'render_import_page')
+        );
+    }
+
+    public function render_import_page() {
+        ?>
+        <div class="wrap">
+            <h1><?php echo esc_html(get_admin_page_title()); ?></h1>
+            
+            <h2><?php _e('Import InPrint Protocol', 'studiou-wc-ord-print-statuses'); ?></h2>
+            <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" enctype="multipart/form-data">
+                <input type="hidden" name="action" value="import_inprint_protocol">
+                <?php wp_nonce_field('import_inprint_protocol', 'import_inprint_protocol_nonce'); ?>
+                <input type="file" name="inprint_csv" accept=".csv" required>
+                <?php submit_button(__('Import InPrint Protocol', 'studiou-wc-ord-print-statuses')); ?>
+            </form>
+
+            <h2><?php _e('Import Delivered Protocol', 'studiou-wc-ord-print-statuses'); ?></h2>
+            <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" enctype="multipart/form-data">
+                <input type="hidden" name="action" value="import_delivered_protocol">
+                <?php wp_nonce_field('import_delivered_protocol', 'import_delivered_protocol_nonce'); ?>
+                <input type="file" name="delivered_csv" accept=".csv" required>
+                <?php submit_button(__('Import Delivered Protocol', 'studiou-wc-ord-print-statuses')); ?>
+            </form>
+        </div>
+        <?php
+    }
+
+    public function handle_import_inprint_protocol() {
+        if (!current_user_can('manage_woocommerce')) {
+            wp_die(__('You do not have sufficient permissions to access this page.', 'studiou-wc-ord-print-statuses'));
+        }
+
+        check_admin_referer('import_inprint_protocol', 'import_inprint_protocol_nonce');
+
+        if (!isset($_FILES['inprint_csv'])) {
+            wp_die(__('No file uploaded.', 'studiou-wc-ord-print-statuses'));
+        }
+
+        $file = $_FILES['inprint_csv'];
+        $csv_data = $this->parse_csv($file['tmp_name']);
+
+        if (!$csv_data) {
+            wp_die(__('Error parsing CSV file.', 'studiou-wc-ord-print-statuses'));
+        }
+
+        $updated_count = 0;
+        $errors = array();
+
+        foreach ($csv_data as $row) {
+            if (!isset($row['Order No']) || !isset($row['ExternalOrder']) || !isset($row['ExternalOrderDate'])) {
+                $errors[] = __('Invalid row format in CSV.', 'studiou-wc-ord-print-statuses');
+                continue;
+            }
+
+            $order_id = wc_get_order_id_by_order_number($row['Order No']);
+            if (!$order_id) {
+                $errors[] = sprintf(__('Order %s not found.', 'studiou-wc-ord-print-statuses'), $row['Order No']);
+                continue;
+            }
+
+            $order = wc_get_order($order_id);
+            $order->update_status('wc-in-print');
+            $order->update_meta_data('in_print_date', current_time('mysql'));
+            $order->update_meta_data('external_ref_ord_no', $row['ExternalOrder']);
+            $order->update_meta_data('external_ref_ord_date', $row['ExternalOrderDate']);
+            $order->save();
+
+            $updated_count++;
+        }
+
+        $message = sprintf(__('%d orders updated successfully.', 'studiou-wc-ord-print-statuses'), $updated_count);
+        if (!empty($errors)) {
+            $message .= ' ' . sprintf(__('%d errors occurred: %s', 'studiou-wc-ord-print-statuses'), count($errors), implode(', ', $errors));
+        }
+
+        wp_redirect(add_query_arg('message', urlencode($message), admin_url('admin.php?page=studiou-import-protocols')));
+        exit;
+    }
+
+    public function handle_import_delivered_protocol() {
+        if (!current_user_can('manage_woocommerce')) {
+            wp_die(__('You do not have sufficient permissions to access this page.', 'studiou-wc-ord-print-statuses'));
+        }
+
+        check_admin_referer('import_delivered_protocol', 'import_delivered_protocol_nonce');
+
+        if (!isset($_FILES['delivered_csv'])) {
+            wp_die(__('No file uploaded.', 'studiou-wc-ord-print-statuses'));
+        }
+
+        $file = $_FILES['delivered_csv'];
+        $csv_data = $this->parse_csv($file['tmp_name']);
+
+        if (!$csv_data) {
+            wp_die(__('Error parsing CSV file.', 'studiou-wc-ord-print-statuses'));
+        }
+
+        $updated_count = 0;
+        $errors = array();
+
+        foreach ($csv_data as $row) {
+            if (!isset($row['Order No'])) {
+                $errors[] = __('Invalid row format in CSV.', 'studiou-wc-ord-print-statuses');
+                continue;
+            }
+
+            $order_id = wc_get_order_id_by_order_number($row['Order No']);
+            if (!$order_id) {
+                $errors[] = sprintf(__('Order %s not found.', 'studiou-wc-ord-print-statuses'), $row['Order No']);
+                continue;
+            }
+
+            $order = wc_get_order($order_id);
+            $order->update_status('wc-completed');
+            $order->update_meta_data('external_ref_ord_delivered', current_time('mysql'));
+            $order->save();
+
+            $updated_count++;
+        }
+
+        $message = sprintf(__('%d orders updated successfully.', 'studiou-wc-ord-print-statuses'), $updated_count);
+        if (!empty($errors)) {
+            $message .= ' ' . sprintf(__('%d errors occurred: %s', 'studiou-wc-ord-print-statuses'), count($errors), implode(', ', $errors));
+        }
+
+        wp_redirect(add_query_arg('message', urlencode($message), admin_url('admin.php?page=studiou-import-protocols')));
+        exit;
+    }
+
+    private function parse_csv($file_path) {
+        $csv_data = array();
+        if (($handle = fopen($file_path, "r")) !== FALSE) {
+            $headers = fgetcsv($handle, 1000, ",");
+            while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
+                $csv_data[] = array_combine($headers, $data);
+            }
+            fclose($handle);
+        }
+        return $csv_data;
+    }
+}

+ 66 - 0
studiou-wc-ord-print-statuses/includes/class-order-fields-manager.php

@@ -0,0 +1,66 @@
+<?php
+// Manages custom order fields.
+// visualized
+
+class Order_Fields_Manager {
+    public function __construct() {
+        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'));
+    }
+
+    public function display_custom_order_fields($order) {
+        ?>
+        <div class="order_data_column">
+            <h4><?php _e('Print Information', 'studiou-wc-ord-print-statuses'); ?></h4>
+            <?php
+            woocommerce_wp_text_input(array(
+                'id' => 'to_print_date',
+                'label' => __('Prepare To Print Date', 'studiou-wc-ord-print-statuses'),
+                'type' => 'datetime-local',
+                'value' => $order->get_meta('to_print_date'),
+                'wrapper_class' => 'form-field-wide'
+            ));
+            woocommerce_wp_text_input(array(
+                'id' => 'in_print_date',
+                'label' => __('In Print Date', 'studiou-wc-ord-print-statuses'),
+                'type' => 'datetime-local',
+                'value' => $order->get_meta('in_print_date'),
+                'wrapper_class' => 'form-field-wide'
+            ));
+            woocommerce_wp_text_input(array(
+                'id' => 'external_ref_ord_no',
+                'label' => __('External Order Number', 'studiou-wc-ord-print-statuses'),
+                'value' => $order->get_meta('external_ref_ord_no'),
+                'wrapper_class' => 'form-field-wide'
+            ));
+            woocommerce_wp_text_input(array(
+                'id' => 'external_ref_ord_delivered',
+                'label' => __('External Order Delivered', 'studiou-wc-ord-print-statuses'),
+                'type' => 'datetime-local',
+                'value' => $order->get_meta('external_ref_ord_delivered'),
+                'wrapper_class' => 'form-field-wide'
+            ));
+            ?>
+        </div>
+        <?php
+    }
+
+    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']));
+        }
+        
+        $order->save();
+    }
+}

+ 63 - 0
studiou-wc-ord-print-statuses/includes/class-order-search-manager.php

@@ -0,0 +1,63 @@
+<?php
+// Extends order search functionality.
+
+class Order_Search_Manager {
+    public function __construct() {
+        add_filter('manage_woocommerce_page_wc-orders_columns', array($this, 'add_external_ref_ord_no_to_search'));
+        add_action('manage_woocommerce_page_wc-orders_custom_column', array($this, 'add_external_ref_ord_no_search_field'));
+        //add_filter('parse_query', array($this, 'process_external_ref_ord_no_search'));
+    }
+
+    /**
+     * Adds the external_ref_ord_no to the list of searchable fields for orders.
+     *
+     * @param array $search_fields The current array of searchable fields.
+     * @return array The updated array of searchable fields.
+     */
+    public function add_external_ref_ord_no_to_search($search_fields) {
+        $search_fields[] = '_external_ref_ord_no';
+        return $search_fields;
+    }
+
+    /**
+     * Adds a search field for external_ref_ord_no in the order list page.
+     */
+    public function add_external_ref_ord_no_search_field() {
+        global $typenow;
+        if ('shop_order' === $typenow) {
+            $external_ref_ord_no = isset($_GET['external_ref_ord_no']) ? sanitize_text_field($_GET['external_ref_ord_no']) : '';
+            ?>
+            <input type="text" name="external_ref_ord_no" value="<?php echo esc_attr($external_ref_ord_no); ?>" placeholder="<?php esc_attr_e('Search by External Order Number', 'studiou-wc-ord-print-statuses'); ?>">
+            <?php
+        }
+    }
+
+    /**
+     * Processes the external_ref_ord_no search query.
+     *
+     * @param WP_Query $query The current WordPress query object.
+     * @return WP_Query The modified query object.
+     */
+    public function process_external_ref_ord_no_search($query) {
+        global $pagenow, $typenow;
+
+        if ('edit.php' !== $pagenow || 'shop_order' !== $typenow || !$query->is_main_query()) {
+            return $query;
+        }
+
+        if (!empty($_GET['external_ref_ord_no'])) {
+            $external_ref_ord_no = sanitize_text_field($_GET['external_ref_ord_no']);
+            $meta_query = $query->get('meta_query') ? $query->get('meta_query') : array();
+
+            $meta_query[] = array(
+                'key' => '_external_ref_ord_no',
+                'value' => $external_ref_ord_no,
+                'compare' => 'LIKE',
+            );
+
+            $query->set('meta_query', $meta_query);
+        }
+
+        return $query;
+    }
+}

+ 65 - 0
studiou-wc-ord-print-statuses/includes/class-order-status-manager.php

@@ -0,0 +1,65 @@
+<?php
+// Handles custom order status registration and integration.
+class Order_Status_Manager {
+    private $custom_statuses;
+
+    public function __construct() {
+        $this->custom_statuses = array(
+            'wc-to-print' => array(
+                'label' => _x('Prepare to Printing', 'Order status', 'studiou-wc-ord-print-statuses'),
+                'label_count' => _n_noop('Prepare to Printing <span class="count">(%s)</span>', 'Prepare to Printing <span class="count">(%s)</span>', 'studiou-wc-ord-print-statuses')
+            ),
+            'wc-in-print' => array(
+                'label' => _x('In Printing', 'Order status', 'studiou-wc-ord-print-statuses'),
+                'label_count' => _n_noop('In Printing <span class="count">(%s)</span>', 'In Printing <span class="count">(%s)</span>', 'studiou-wc-ord-print-statuses')
+            )
+        );
+
+        add_action('init', array($this, 'register_custom_order_statuses'));
+        add_filter('wc_order_statuses', array($this, 'add_custom_order_statuses_to_list'));
+        add_action('woocommerce_order_status_changed', array($this, 'handle_status_transitions'), 10, 3);
+    }
+
+    public function register_custom_order_statuses() {
+        foreach ($this->custom_statuses as $status_slug => $status_args) {
+            register_post_status($status_slug, array(
+                'label' => $status_args['label'],
+                'public' => true,
+                'exclude_from_search' => false,
+                'show_in_admin_all_list' => true,
+                'show_in_admin_status_list' => true,
+                'label_count' => $status_args['label_count']
+            ));
+        }
+    }
+
+    public function add_custom_order_statuses_to_list($order_statuses) {
+        $new_order_statuses = array();
+
+        foreach ($order_statuses as $key => $status) {
+            $new_order_statuses[$key] = $status;
+
+            if ($key === 'wc-processing') {
+                foreach ($this->custom_statuses as $status_slug => $status_args) {
+                    $new_order_statuses[$status_slug] = $status_args['label'];
+                }
+            }
+        }
+
+        return $new_order_statuses;
+    }
+
+    public function handle_status_transitions($order_id, $old_status, $new_status) {
+        // Handle status transitions here
+        // For example:
+        if ($new_status === 'to-print') {
+            update_post_meta($order_id, 'to-print-date', current_time('mysql'));
+        } elseif ($new_status === 'in-print') {
+            update_post_meta($order_id, 'in-print-date', current_time('mysql'));
+        }
+    }
+
+    public function get_custom_statuses() {
+        return $this->custom_statuses;
+    }
+}

+ 26 - 496
studiou-wc-ord-print-statuses/studiou-wc-ord-print-statuses.php

@@ -11,63 +11,47 @@
 
 defined('ABSPATH') or die('Direct access not allowed!');
 
-
-/**
- * Main plugin class
- */
+// Main plugin class
 class Studiou_WC_Ord_Print_Statuses {
+    private $order_status_manager;
+    private $order_fields_manager;
+    private $order_search_manager;
+    private $bulk_actions_manager;
+    private $custom_columns_manager;
+    private $import_manager;
 
-    /**
-     * Constructor
-     */
     public function __construct() {
         add_action('plugins_loaded', array($this, 'init'));
-        add_action('pre_get_posts', array($this, 'custom_columns_orderby'));
     }
 
-    /**
-     * Initialize the plugin
-     */
     public function init() {
-        error_log('Plugin initializing...');
-        // Check if WooCommerce is active
         if (!class_exists('WooCommerce')) {
             add_action('admin_notices', array($this, 'woocommerce_missing_notice'));
             return;
         }
-        
-        // 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();
-        //$this->log_filter_names();
-        $this->log_woocommerce_filter_names();
 
-        // Log a debug message
-        error_log('Plugin initialized');
+        $this->load_dependencies();
+        $this->initialize_managers();
     }
 
-    function log_filter_names() {
-        global $wp_filter;
-        $filter_names = array_keys($wp_filter);
-        error_log('Current WordPress filter hooks: ' . print_r($filter_names, true));
+    private function load_dependencies() {
+        require_once plugin_dir_path(__FILE__) . 'includes/class-order-status-manager.php';
+        require_once plugin_dir_path(__FILE__) . 'includes/class-order-fields-manager.php';
+        require_once plugin_dir_path(__FILE__) . 'includes/class-order-search-manager.php';
+        require_once plugin_dir_path(__FILE__) . 'includes/class-bulk-actions-manager.php';
+        require_once plugin_dir_path(__FILE__) . 'includes/class-custom-columns-manager.php';
+        require_once plugin_dir_path(__FILE__) . 'includes/class-import-manager.php';
     }
-    function log_woocommerce_filter_names() {
-        global $wp_filter;
-        $all_filter_names = array_keys($wp_filter);
-        $woocommerce_filter_names = array_filter($all_filter_names, function($name) {
-            return (stripos($name, 'woocommerce') !== false) || (stripos($name, 'wc') !== false);
-        });
-        if (!empty($woocommerce_filter_names)) {
-            error_log('Current WooCommerce filter hooks: ' . print_r($woocommerce_filter_names, true));
-        }
+
+    private function initialize_managers() {
+        $this->order_status_manager = new Order_Status_Manager();
+        $this->order_fields_manager = new Order_Fields_Manager();
+        $this->bulk_actions_manager = new Bulk_Actions_Manager();
+        $this->custom_columns_manager = new Custom_Columns_Manager();
+        $this->import_manager = new Import_Manager();
+        $this->order_search_manager = new Order_Search_Manager();
     }
-    /**
-     * Display a notice if WooCommerce is not active
-     */
+
     public function woocommerce_missing_notice() {
         ?>
         <div class="error">
@@ -75,461 +59,7 @@ class Studiou_WC_Ord_Print_Statuses {
         </div>
         <?php
     }
-
-    /**
-     * 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'));
-    }
-
-    /**
-     * Register custom order statuses
-     */
-    public function register_custom_order_statuses() {
-        register_post_status('wc-to-print', array(
-            'label' => _x('Prepare to Printing', 'Order status', 'studiou-wc-ord-print-statuses'),
-            'public' => true,
-            'exclude_from_search' => false,
-            'show_in_admin_all_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>')
-        ));
-
-        register_post_status('wc-in-print', array(
-            'label' => _x('In Printing', 'Order status', 'studiou-wc-ord-print-statuses'),
-            'public' => true,
-            'exclude_from_search' => false,
-            'show_in_admin_all_list' => true,
-            'show_in_admin_status_list' => true,
-            'label_count' => _n_noop('In Printing <span class="count">(%s)</span>', 'In Printing <span class="count">(%s)</span>')
-        ));
-    }
-
-    /**
-     * Add custom order statuses to the list of WooCommerce order statuses
-     */
-    public function add_custom_order_statuses_to_list($order_statuses) {
-        $new_order_statuses = array();
-
-        foreach ($order_statuses as $key => $status) {
-            $new_order_statuses[$key] = $status;
-
-            if ($key === 'wc-processing') {
-                $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');
-            }
-        }
-
-        return $new_order_statuses;
-    }
-
-    /**
-     * Add custom order fields to order detail page
-     */
-    private function add_custom_order_fields() {
-        // to detail page
-        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'));
-
-    }
-
-    /**
-     * 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']));
-        }
-
-        $order->save();
-    }
-
-    /**
-     * Modify order search to include external reference order number
-     */
-    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) {
-        error_log('add_external_ref_ord_no_to_search - called');
-        $search_fields[] = 'external_ref_ord_no';
-        return $search_fields;
-    }
-
-    /**
-     * Add bulk actions to the orders list
-     */
-    private function add_bulk_actions() {
-        //add_filter('bulk_actions-edit-shop_order', array($this, 'register_bulk_actions'));
-        add_filter('bulk_actions-woocommerce_page_wc-orders', array($this, 'register_bulk_actions'));
-        add_filter('handle_bulk_actions-woocommerce_page_wc-orders', 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;
-    }
-
-    /**
-     * 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;
-    }
-
-    /**
-     * Handle the "Prepare to Printing Export" bulk action
-     */
-    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) {
-            $order = wc_get_order($post_id);
-            $order->update_status('wc-to-print');
-            $order->update_meta_data('to_print_date', current_time('mysql'));
-            $order->save();
-        }
-    }
-
-    /**
-     * 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();
-        }
-    }
-
-    /**
-     * Add custom columns to the orders list
-     */
-    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);
-        add_filter('manage_edit-shop_order_sortable_columns', array($this, 'make_custom_columns_sortable'));
-        add_filter('manage_woocommerce_page_wc-orders_custom_column', array($this, 'set_custom_columns_default_visibility'));
-    }
-
-    /**
-     * Add custom columns to the orders list table
-     */
-    public function add_custom_shop_order_column($columns) {
-        $new_columns = array();
-
-        foreach ($columns as $column_name => $column_info) {
-            $new_columns[$column_name] = $column_info;
-
-            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');
-                error_log('add_custom_shop_order_column - columns add');
-            }
-            error_log('add_custom_shop_order_column - finished');
-        }
-
-        return $new_columns;
-    }
-
-    public function set_custom_columns_default_visibility($hidden) {
-        if (!is_array($hidden)) {
-            $hidden = array();
-        }
-    
-        // Remove our custom columns from the hidden list if they're there
-        $hidden = array_diff($hidden, array('to_print_date', 'in_print_date', 'external_ref_ord_no'));
-    
-        // Optionally, if you want these columns hidden by default, add them to the $hidden array
-        // $hidden[] = 'to_print_date';
-        // $hidden[] = 'in_print_date';
-        // $hidden[] = 'external_ref_ord_no';
-        error_log('set_custom_columns_default_visibility - finished');
-        return $hidden;
-    }
-
-    public function make_custom_columns_sortable($columns) {
-        $columns['to_print_date'] = 'to_print_date';
-        $columns['in_print_date'] = 'in_print_date';
-        $columns['external_ref_ord_no'] = 'external_ref_ord_no';
-        return $columns;
-    }
-
-    public function custom_columns_orderby($query) {
-        if (!is_admin() || !$query->is_main_query() || $query->get('post_type') !== 'shop_order') {
-            return;
-        }
-    
-        $orderby = $query->get('orderby');
-    
-        switch ($orderby) {
-            case 'to_print_date':
-            case 'in_print_date':
-            case 'external_ref_ord_no':
-                $query->set('meta_key', $orderby);
-                $query->set('orderby', 'meta_value');
-                break;
-        }
-    }
-
-
-    /**
-     * 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
-    }
-
-    /**
-     * Handle the import of InPrint protocol
-     */
-    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;
-    }
 }
 
-
 // Initialize the plugin
- new Studiou_WC_Ord_Print_Statuses();
+new Studiou_WC_Ord_Print_Statuses();