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 (%s)', 'Prepare to Printing (%s)', '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 (%s)', 'In Printing (%s)', '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; } }