I began to have problems with action woocommerce_order_status_changed and it never triggered for any of my custom statuses.
I found the hook is used in class-wc-order.php only when $status_transition is not false.
if ( $status_transition ) {
try {
do_action( 'woocommerce_order_status_' . $status_transition['to'], $this->get_id(), $this );
if ( ! empty( $status_transition['from'] ) ) {
/* translators: 1: old order status 2: new order status */
$transition_note = sprintf( __( 'Order status changed from %1$s to %2$s.', 'woocommerce' ), wc_get_order_status_name( $status_transition['from'] ), wc_get_order_status_name( $status_transition['to'] ) );
// Note the transition occurred.
$this->add_status_transition_note( $transition_note, $status_transition );
do_action( 'woocommerce_order_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
do_action( 'woocommerce_order_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
// Etc...
All the custom statuses I made works and are shown on WooCommerce admin page. For adding the status I use:
function register_statuses()
{
register_post_status('wc-payment-await', array(
'label' => 'Awaiting payment',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('Awaiting payment <span class="count">(%s)</span>', 'Awaiting payment <span class="count">(%s)</span>', 'woocommerce')
));
// more statuses here
}
add_action('init', 'register_statuses');
I found out that $status_transition is always false whenever I save order with new status. This feature worked until I have recently upgraded WooCommerce. Also I tried all other hooks for status change or transition none of which worked. Any advice is appreciated.