option_key, []); } // Register statuses with WooCommerce public function register_custom_statuses() { foreach ($this->get_statuses() as $slug => $label) { register_post_status($slug, [ 'label' => $label, 'public' => true, 'exclude_from_search' => false, 'show_in_admin_all_list' => true, 'show_in_admin_status_list' => true, 'label_count' => _n_noop("$label (%s)", "$label (%s)") ]); } } // Add to WooCommerce list public function add_to_wc_statuses($statuses) { foreach ($this->get_statuses() as $slug => $label) { $statuses[$slug] = $label; } return $statuses; } // Handle form: add/delete public function handle_form_submit() { if (!current_user_can('manage_woocommerce')) return; // Add new status if (isset($_POST['absoftlab_add_status'])) { check_admin_referer('absoftlab_add_status'); $label = sanitize_text_field($_POST['status_label']); $slug = 'wc-' . sanitize_title($label); $statuses = $this->get_statuses(); $statuses[$slug] = $label; update_option($this->option_key, $statuses); wp_redirect(admin_url('admin.php?page=absoftlab-order-status&added=1')); exit; } // Delete status if (isset($_GET['absoftlab_delete']) && isset($_GET['_wpnonce'])) { if (wp_verify_nonce($_GET['_wpnonce'], 'absoftlab_delete_status')) { $slug = sanitize_text_field($_GET['absoftlab_delete']); $statuses = $this->get_statuses(); unset($statuses[$slug]); update_option($this->option_key, $statuses); wp_redirect(admin_url('admin.php?page=absoftlab-order-status&deleted=1')); exit; } } } // Admin Page HTML public function settings_page() { $statuses = $this->get_statuses(); ?>
Status added successfully!
Status deleted successfully!
Slug | Label | Action |
---|---|---|
Delete |