woothemes/woocommerce — pull request #6791 by ragulka (2014-11-19 12:36:40+00:00)
Title: DRY status actions, support custom status handling

DRY up order status bulk actions and AJAX actions. Provides also support for custom order status handling.

NB! Changes the AJAX action name for marking an order with a status: instead of using named actions like `mark_order_processing`, it uses a generic name: `mark_order_status`. This means that whoever calls this AJAX action needs to supply the status via URL query params, like `?action=mark_order_status&status=completed`.
I'm fairly sure it does not break anything in core, but I can't speak for extensions that might possibly use these named actions. If you think this might be a problem, I can add named actions for `completed` and `processing` for 100% backwards compatibility.

What follows is a longer reasoning behind this PR:
There are some built-in bulk actions and single-order actions regarding order statuses. These are: Mark complete, Mark processing, Mark on-hold. While implementing a few custom order statuses I noticed that core does some code duplication here and there. I realized some of it could be refactored to be DRYer and also, provide a few hooks so that custom order statuses could be registered for both bulk an AJAX actions.

First of all, these methods are practically identical: https://github.com/woothemes/woocommerce/blob/master/includes/class-wc-ajax.php#L344-L392
These could be refactored into a single method that gets the status from request params, and possibly validates it against `wc_get_order_statuses()`. This would automatically enable marking orders with any status via AJAX without having to duplicate any code. Core would still only provide action buttons for processing and complete, of course.

Second, we can refactor [this](https://github.com/woothemes/woocommerce/blob/master/includes/admin/class-wc-admin-post-types.php#L1203-L1244), so that, again, it would work for other order statuses as well.