Vladimir Kyatipov
Vladimir Kyatipov

Reputation: 736

Allow order to be fully editable while using a custom order status in WooCommerce

I have a bug with the edit quantity in an order while using a custom status. The edit arrow seems to have disappeared?

Is there another value I can include while registering a custom order status?

Here is my code:

// Register new status 'To order' 
function register_new_on_hold_order_status2() {
    register_post_status( 'wc-to-order', array(
        'label'                     => 'To order',
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'To order (%s)', 'To order (%s)' )
    ) );
}
add_action( 'init', 'register_new_on_hold_order_status2' );

// Add to list of WC Order statuses
function add_on_hold_new_to_order_statuses2( $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-processing' === $key ) {   // Here we Define after which to be added
            $new_order_statuses['wc-to-order'] = 'To order';
        }
    }
 
    return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_on_hold_new_to_order_statuses2' );

enter image description here

Upvotes: 1

Views: 767

Answers (1)

7uc1f3r
7uc1f3r

Reputation: 29614

This is not a bug, certain order statuses such as processing do not allow the order to be editable. To change this you can use the wc_order_is_editable hook

So you get:

function filter_wc_order_is_editable( $editable, $order ) {
    // Compare
    if ( $order->get_status() == 'your-status' ) {
        $editable = true;
    }
    
    return $editable;
}
add_filter( 'wc_order_is_editable', 'filter_wc_order_is_editable', 10, 2 );

Note: use woocommerce_register_shop_order_post_statuses opposite init while registering a custom order status as applied in the 2nd part of this answer

Upvotes: 4

Related Questions