Custom status orders do not show in Orders list
-
I cannot for the life of me figure out why this is happening, but it did not happen on older version of WooCommerce.
I have a custom order status that I create using the following code:
function register_awaiting_shipment_order_status() { register_post_status( 'wc-shipment', array( 'label' => 'Preparing Shipment', 'public' => true, 'exclude_from_search' => false, 'show_in_admin_all_list' => true, 'show_in_admin_status_list' => true, 'label_count' => _n_noop( 'Preparing Shipment <span class="count">(%s)</span>', 'Preparing Shipment <span class="count">(%s)</span>' ) ) ); } add_action( 'init', 'register_awaiting_shipment_order_status' ); // Add to list of WC Order statuses function add_awaiting_shipment_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-processing' === $key ) { $new_order_statuses['wc-shipment'] = 'Preparing Shipment'; } } return $new_order_statuses; } add_filter( 'wc_order_statuses', 'add_awaiting_shipment_to_order_statuses' );
And if I go into an order and manually change it to ‘Preparing Shipment’, there is no issue and everything works as expected.
However, I have a button that I have coded to update the status programmatically via AJAX using this:
$order = new WC_Order($orderid); if (!$order) exit(); $order->update_status('wc-shipment');
It all works, but when it is done programmatically, the order vanishes from the orders list, and I can’t even search for it by the exact order number. The only way to access that order is to manually enter the order ID in the URL to edit it. When editing it, the order status has been successfully updated to ‘Preparing Shipment’. Then, if I manually save/update the order without changing anything, it shows up in the order list fine.
Finally, if I run the exact same update_status code for a built in WooCommerce status, it all works as expected.
So what is it about the way I am updating or creating the custom status that is somehow missing some step that allows WooCommerce to notice it? This never happened in older versions, and I think it stopped working once WooCommerce 4 came out.
Any advice would be greatly appreciated, as this is preventing me from being able to update stuff.
- The topic ‘Custom status orders do not show in Orders list’ is closed to new replies.