I created a custom order status in WooCommerce with the following code:

function register_packed_order_status() {
    register_post_status( 'wc-goods-packed', array(
        'label'                     => 'Gepackt',
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'Gepackt <span class="count">(%s)</span>', 'Gepackt <span class="count">(%s)</span>' )
    ) );
}
add_action( 'init', 'register_packed_order_status' );

After that I put the status in the right order in the drop down:

// Add to list of WC Order statuses
function add_packed_to_order_statuses( $order_statuses ) {
    $new_order_statuses = array();

    // add new order status after processing
    foreach ( $order_statuses as $key => $status ) {

        $new_order_statuses[ $key ] = $status;

        if ( 'wc-on-hold' === $key ) {
            $new_order_statuses['wc-goods-packed'] = 'Gepackt';
        }
    }

    return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_packed_to_order_statuses' );

That works – I can select the order status in the product edit screen and save the order. In order to prevent the store manager to always need to edit the order detail screen, I want to include a button in the order action column in the order overview screen. I do this with the following code:

add_filter( 'woocommerce_admin_order_actions', 'add_cancel_order_actions_button', PHP_INT_MAX, 2 );
function add_cancel_order_actions_button( $actions, $the_order ) {
    if ( ! $the_order->has_status( array( 'wc-goods-packed' ) ) ) {
        $actions['wc-goods-packed'] = array(
            'url'       => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=wc-goods-packed&order_id=' . $the_order->id ), 'woocommerce-mark-order-status' ),
            'name'      => __( 'Gepackt', 'woocommerce' ),
            'action'    => "view packed", // setting "view" for proper button CSS
        );
    }
    return $actions;
}

I can see the button in the overview (http://d.pr/i/ZC1t) and I can click it, but the status does not change. Do you know why this happens? I can not see what is wrong with my piece of code.

Thanks!

Read more here: WooCommerce – Custom admin order status is not working


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: