|
@@ -11,63 +11,47 @@
|
|
|
|
|
|
|
|
defined('ABSPATH') or die('Direct access not allowed!');
|
|
defined('ABSPATH') or die('Direct access not allowed!');
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * Main plugin class
|
|
|
|
|
- */
|
|
|
|
|
|
|
+// Main plugin class
|
|
|
class Studiou_WC_Ord_Print_Statuses {
|
|
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() {
|
|
public function __construct() {
|
|
|
add_action('plugins_loaded', array($this, 'init'));
|
|
add_action('plugins_loaded', array($this, 'init'));
|
|
|
- add_action('pre_get_posts', array($this, 'custom_columns_orderby'));
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Initialize the plugin
|
|
|
|
|
- */
|
|
|
|
|
public function init() {
|
|
public function init() {
|
|
|
- error_log('Plugin initializing...');
|
|
|
|
|
- // Check if WooCommerce is active
|
|
|
|
|
if (!class_exists('WooCommerce')) {
|
|
if (!class_exists('WooCommerce')) {
|
|
|
add_action('admin_notices', array($this, 'woocommerce_missing_notice'));
|
|
add_action('admin_notices', array($this, 'woocommerce_missing_notice'));
|
|
|
return;
|
|
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() {
|
|
public function woocommerce_missing_notice() {
|
|
|
?>
|
|
?>
|
|
|
<div class="error">
|
|
<div class="error">
|
|
@@ -75,461 +59,7 @@ class Studiou_WC_Ord_Print_Statuses {
|
|
|
</div>
|
|
</div>
|
|
|
<?php
|
|
<?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
|
|
// Initialize the plugin
|
|
|
- new Studiou_WC_Ord_Print_Statuses();
|
|
|
|
|
|
|
+new Studiou_WC_Ord_Print_Statuses();
|