Scriptfeeds Blog
  • Blog
  • WordPress
    • Woocommerce
    • WordPress Errors
    • WordPress Plugins
  • Development
    • WordPress Themes
  • Hire us
Cart / $0.00

No products in the cart.

No Result
View All Result
Scriptfeeds Blog
  • Blog
  • WordPress
    • Woocommerce
    • WordPress Errors
    • WordPress Plugins
  • Development
    • WordPress Themes
  • Hire us
Cart / $0.00

No products in the cart.

No Result
View All Result
Scriptfeeds Blog
No Result
View All Result
Home Wordpress

Easy steps to add and edit custom order status in WooCommerce

Scriptfeeds by Scriptfeeds
July 23, 2022
in Wordpress, Woocommerce
0
84
SHARES
Share on FacebookShare on TwitterWhatsapp this Blog

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

  • Add below code to create new custom order status in WooCommerce orders.
  • Add below code to remove any order status in WooCommerce orders.
  • You can also Edit an existing order status on WooCommerce

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.

custom order status in WooCommerce

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.

Connect with Developer
Loading
Tags: Add custom WooCommerce order statusEdit WooCommerce order statusRemove WooCommerce order status
Share34Tweet21Send

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

I agree to the Terms & Conditions and Privacy Policy.

Scriptfeeds Blog

© 2022 Scriptfeeds

Blog Categories

  • WordPress
  • Development
  • Reviews
  • Marketing

Connect us on

No Result
View All Result
  • Blog
  • WordPress
    • Woocommerce
    • WordPress Errors
    • WordPress Plugins
  • Development
    • WordPress Themes
  • Hire us

© 2022 Scriptfeeds

This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.