|
|
@@ -9,58 +9,73 @@
|
|
|
* 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() {
|
|
|
- // 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(
|
|
|
- 'label' => 'Prepare to Printing',
|
|
|
+ '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' => 'In Printing',
|
|
|
+ 'label' => _x('In Printing', 'Order status', 'studiou-wc-ord-print-statuses'),
|
|
|
'public' => true,
|
|
|
'exclude_from_search' => false,
|
|
|
'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();
|
|
|
|
|
|
- // Add the custom status after the "Processing" status
|
|
|
foreach ($order_statuses as $key => $status) {
|
|
|
$new_order_statuses[$key] = $status;
|
|
|
+
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
-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) {
|
|
|
$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();
|
|
|
|
|
|
foreach ($columns as $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;
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 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();
|