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.
2
Answers
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.
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: