Recently we added an extra custom order status in WooCommerce Products for one of our client. These custom order status are very helpful to provide clarity of order status for the customers.
Table of Contents
By default, WooCommerce offers some predefined order status but we can add more order status with the help of codes which we gonna provide you. You can set these custom order status in WooCommerce status as per your choice which will be visible to the customers. So lets quickly jumps code section.
Please note that you have to add these codes in functions.php file of your child theme in WordPress.
WooCommerce orders are treated as a special custom post type. so in order to include our custom order status in WooCommerce order status in the available status list, we need to use the register_post_status()
WP inbuilt function.
Add below code to create new custom order status in WooCommerce orders.
Here we are creating new order status “approve”. you can define any text or label.
// Register new status
function register_approve_order_status() {
register_post_status( 'wc-approve', array(
'label' => 'approve',
'public' => true,
'show_in_admin_status_list' => true,
'show_in_admin_all_list' => true,
'exclude_from_search' => false,
'label_count' => _n_noop( 'approve (%s)', 'approve (%s)' )
) );
}
// Add custom status to order status list
function add_approve_order_statuses( $order_statuses ) {
$new_order_statuses = array();
foreach ( $order_statuses as $key => $status ) {
$new_order_statuses[ $key ] = $status;
if ( 'wc-on-hold' === $key ) {
$new_order_statuses['wc-approve'] = 'approve';
}
}
return $new_order_statuses;
}
add_action( 'init', 'register_approve_order_status' );
add_filter( 'wc_order_statuses', 'add_approve_order_statuses' );
Add below code to remove any order status in WooCommerce orders.
Use the following script in order to remove an existing order status. This will work for both default order statuses and for custom order status in WooCommerce
function scriptfeeds_remove_status( $statuses ) {
if( isset( $statuses['wc-refunded'] ) ){
unset( $statuses['wc-refunded'] );
}
return $statuses;
}
add_filter( 'wc_order_statuses', 'scriptfeeds_remove_status' );
You can also Edit an existing order status on WooCommerce
The following sample code will edit two order stats: “processing” and “completed”, changing them to “in progress” and “delivered”:
function scriptfeeds_rename_status( $order_statuses ) {
foreach ( $order_statuses as $key => $status ) {
if ( 'wc-processing' === $key ) {
$order_statuses['wc-processing'] = _x( 'In progress', 'Order status', 'woocommerce' );
}
if ( 'wc-completed' === $key ) {
$order_statuses['wc-completed'] = _x( 'Delivered', 'Order status', 'woocommerce' );
}
}
return $order_statuses;
}
add_filter( 'wc_order_statuses', 'scriptfeeds_rename_status' );
So that’s how you can edit, create or delete any WooCommerce order status. So give it a try and let us know how it goes in the comments. If you need any more customization regarding WooCommerce order status, please let us know in comment section or fill the form below.