skip to Main Content

When I change the status of an order to a new custom status, it returns to the status it had before.

add_filter(
    'wc_order_statuses',
    function ( $order_statuses ) {
        $new_order_statuses = array();
        foreach ( $order_statuses as $key => $status ) {
            $new_order_statuses[ $key ] = $status;
            if ( 'wc-processing' === $key ) {
                $new_order_statuses['wc-intransit-shipment'] = __( 'Shipment in Transit', 'wc-kshippingargentina' );
            }
        }
        return $new_order_statuses;
    }
);

add_action(
    'init',
    function () {
        register_post_status(
            'wc-intransit-shipment',
            array(
                'label'                     => __( 'Shipment in Transit', 'wc-kshippingargentina' ),
                'public'                    => true,
                'show_in_admin_status_list' => true,
                'show_in_admin_all_list'    => true,
                'exclude_from_search'       => false,
                // translators: count.
                'label_count'               => _n_noop( 'Shipment in Transit <span class="count">(%s)</span>', 'Shipment in Transit <span class="count">(%s)</span>' ),
            )
        );
    }
);

I do not understand why it happens to me, I leave an attached animation.

My bug

2

Answers


  1. Chosen as BEST ANSWER

    I already found the problem, the size of the ID was very long, it seems that it exceeds the Wordpress character limit. I changed it from 'wc-intransit-shipment' to 'wc-intransit' and the problem was solved.


  2. I think you used the wrong hook, and maybe that’s not helping. On this tutorial for creating custom order statuses, I use ‘woocommerce_register_shop_order_post_statuses’ instead of your ‘register_post_status’.

    So, give this a go:

    add_filter( 'woocommerce_register_shop_order_post_statuses', 'bbloomer_register_custom_order_status' );
     
    function bbloomer_register_custom_order_status( $order_statuses ) {
       $order_statuses['wc-intransit-shipment'] = array(
          'label' => 'Custom Status',
          'public' => false,
          'exclude_from_search' => false,
          'show_in_admin_all_list' => true,
          'show_in_admin_status_list' => true,
          'label_count' => _n_noop( 'Shipment in Transit <span class="count">(%s)</span>', 'Shipment in Transit <span class="count">(%s)</span>', 'woocommerce' ),
    );
       return $order_statuses;
    }
     
    add_filter( 'wc_order_statuses', 'bbloomer_show_custom_order_status_single_order_dropdown' );
     
    function bbloomer_show_custom_order_status_single_order_dropdown( $order_statuses ) {
       $order_statuses['wc-intransit-shipment'] = 'Shipment in Transit';
       return $order_statuses;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search