Here we learn about how to add custom order of WooCommerce statuses.
wc_order_statuses filter hook allows adding, remove or change the order of WooCommerce statuses.
WooCommerce Default Order Status
When you will install fresh woocommerce then you will get below default order status:
- Payment Pending
- Processing
- On Hold
- Completed
- Cancelled
- Refunded
- Failed
Create Custom Order Statuses
Now, We will create custom order status with name “Shipped”.
Just copy and paste below code into your child theme’s functions.php file.
// Register custom order Status
function wppm_register_shipped_order_status() {
register_post_status( 'wc-order-shipped', array(
'label' => 'Shipped',
'public' => true,
'show_in_admin_status_list' => true,
'show_in_admin_all_list' => true,
'exclude_from_search' => false,
'label_count' => _n_noop( 'Shipped <span class="count">(%s)</span>', 'Shipped <span class="count">(%s)</span>' )
) );
}
add_action( 'init', 'wppm_register_shipped_order_status' );
/*** Change Order Statuses Order ***/
function wppm_add_shipped_to_order_statuses( $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-order-shipped'] = 'Shipped';
}
}
return $new_order_statuses;
}
add_filter('wc_order_statuses', 'wppm_add_shipped_to_order_statuses');
Add custom bulk actions to admin orders list
// Add custom bulk actions to admin orders list
add_filter( 'bulk_actions-edit-shop_order', 'wppm_get_shipped_order_status_bulk' );
function wppm_get_shipped_order_status_bulk( $bulk_actions ) {
// Note: "mark_" must be there instead of "wc"
$bulk_actions['mark_order-shipped'] = 'Change status to Shipped';
return $bulk_actions;
}
Conclusion
Thanks for reading 🙏, I hope you will get this code snippet helpful for your project.