An online store might hold different user roles and updating the custom order status to a specific user role may help admin to manage orders easily.
In this post, we will create a custom order status such as ‘Awaiting shipping’ and whenever a ‘subscriber’ user places an order, then the order status skips the default statuses and will be set to a new status ‘Awaiting shipping’ as defined in the code.
Solution: Set a New Order Status For Subscriber User Role
In the below code snippet, by assigning a distinct order status to subscriber orders, the admin can efficiently manage subscription-based orders separately from regular orders.
function ts_register_awaiting_shipment_order_status() { register_post_status( 'wc-pendingwholesale', array( 'label' => 'Awaiting shipment', 'public' => true, 'exclude_from_search' => false, 'show_in_admin_all_list' => true, 'show_in_admin_status_list' => true, 'label_count' => _n_noop( 'Awaiting shipment <span class="count">(%s)</span>', 'Awaiting shipment <span class="count">(%s)</span>' ), ) ); } add_action( 'init', 'ts_register_awaiting_shipment_order_status' ); // Add to list of WC Order statuses function ts_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; $new_order_statuses['wc-pendingwholesale'] = 'Awaiting shipment'; } return $new_order_statuses; } add_filter( 'wc_order_statuses', 'ts_add_awaiting_shipment_to_order_statuses' ); add_action( 'woocommerce_order_status_changed', 'ts_status_changed_processsing_weighted' ); function ts_status_changed_processsing_weighted( $order_id, $checkout = null ) { global $woocommerce; $order = new WC_Order( $order_id ); $user_roles = wp_get_current_user()->roles; if ( in_array( 'subscriber', $user_roles ) ) { $order->update_status( 'pendingwholesale', 'order_note' ); } }
Output
As we have created a new custom order status such as ‘Awaiting Shipping’ this status will now be included to the default order statuses and shown in the status dropdown of edit order page.
![](https://www.tychesoftwares.com/wp-content/uploads/2024/04/custom-order-status-for-user-role-1024x908.png)
Whenever a subscriber logs in and completes an order, the order status will be automatically updated to ‘Awaiting Shipping’, as shown below.
![](https://www.tychesoftwares.com/wp-content/uploads/2024/04/Custom-Order-Status-for-Subscriber-User-Role-1024x419.png)
Addionally, you can incorporate colors and icons to these statuses giving a visual appeal and distinguish the order statuses. Check out this post that will guide you to change WooCommerce order status colors.