blog

How to create custom WooCommerce Order Status

Orders are created in WooCommerce when a customer completes their checkout process. WooCommerce orders have different statuses which lets you know the current position of the order, whether it is complete or its payment is pending, etc. WooCommerce Order Status.
So, WooCommerce has few pre-defined order statuses which helps us to move the order from one stage to another in the processing cycle. Let’s have a look at them.

How to Add WooCommerce Custom Order Actions

If you want to add custom status to your site’s woocommerce plugin, you can very easily do the job. Using the code you see below, you can work very well

It can be done using the following hooked function: Code goes in function.php file of the active child theme (or active theme). Tested and works. WooCommerce Order Status.

 

add_filter( 'wc_order_statuses', 'wc_renaming_order_status_softworks' );

function wc_renaming_order_status_softworks( $order_statuses ) {

    foreach ( $order_statuses as $key => $status ) {
    
    if ( 'wc-processing' === $key ){
            $order_statuses['wc-processing'] = _x( 'ORDER PROCESSING', 'Order status', 'woocommerce' );
    }
    
    if ( 'wc-cancelled' === $key ){
            $order_statuses['wc-cancelled'] = _x( 'PACKAGE CANCELED', 'Order status', 'woocommerce' );
    } 
    
        if ( 'wc-completed' === $key ){
            $order_statuses['wc-completed'] = _x( 'PACKAGE DELIVERED', 'Order status', 'woocommerce' );
    } 

  }
  
    return $order_statuses;
}

function add_package_collected_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-package-collected'] = 'PACKAGE COLLECTED';
        }
    }
    return $new_order_statuses;
}

add_filter( 'wc_order_statuses', 'add_package_collected_order_statuses' );

function add_package_on_the_way_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-package-ontheway'] = 'PACKAGE ON THE WAY';
        }
    }
    return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_package_on_the_way_order_statuses' );

function register_package_softworks_order_status() {
  
    register_post_status( 'wc-processing', array(
        'label'                     => 'ORDER PROCESSING',
        'public'                    => true,
        'show_in_admin_status_list' => true,
        'show_in_admin_all_list'    => true,
        'exclude_from_search'       => false,
        'label_count'               => _n_noop( 'ORDER PROCESSING <span class="count">(%s)</span>', 'ORDER PROCESSING <span class="count">(%s)</span>' )
    ) );
  
    register_post_status( 'wc-package-collected', array(
        'label'                     => 'PACKAGE COLLECTED',
        'public'                    => true,
        'show_in_admin_status_list' => true,
        'show_in_admin_all_list'    => true,
        'exclude_from_search'       => false,
        'label_count'               => _n_noop( 'PACKAGE COLLECTED <span class="count">(%s)</span>', 'PACKAGE COLLECTED <span class="count">(%s)</span>' )
    ) );
  
    register_post_status( 'wc-package-ontheway', array(
        'label'                     => 'PACKAGE ON THE WAY',
        'public'                    => true,
        'show_in_admin_status_list' => true,
        'show_in_admin_all_list'    => true,
        'exclude_from_search'       => false,
        'label_count'               => _n_noop( 'PACKAGE ON THE WAY <span class="count">(%s)</span>', 'PACKAGE ON THE WAY <span class="count">(%s)</span>' )
    ) );
  
    register_post_status( 'wc-completed', array(
        'label'                     => 'PACKAGE DELIVERED',
        'public'                    => true,
        'show_in_admin_status_list' => true,
        'show_in_admin_all_list'    => true,
        'exclude_from_search'       => false,
        'label_count'               => _n_noop( 'PACKAGE DELIVERED <span class="count">(%s)</span>', 'PACKAGE DELIVERED <span class="count">(%s)</span>' )
    ) );
  
    register_post_status( 'wc-cancelled', array(
        'label'                     => 'PACKAGE CANCELED',
        'public'                    => true,
        'show_in_admin_status_list' => true,
        'show_in_admin_all_list'    => true,
        'exclude_from_search'       => false,
        'label_count'               => _n_noop( 'PACKAGE CANCELED <span class="count">(%s)</span>', 'PACKAGE CANCELED <span class="count">(%s)</span>' )
    ) );	
  
}
add_action( 'init', 'register_package_softworks_order_status' );

add_filter( 'bulk_actions-edit-shop_order', 'package_collected_register_bulk_action' );
 
function package_collected_register_bulk_action( $bulk_actions ) {
 
  $bulk_actions['mark_package-collected'] = 'PACKAGE COLLECTED';
  $bulk_actions['mark_package-ontheway'] = 'PACKAGE ON THE WAY';
  return $bulk_actions;
 
}

add_filter( 'bulk_actions-edit-shop_order', 'softworks_renaming_bulk_actions_order_status', 20, 1 );

function softworks_renaming_bulk_actions_order_status( $actions ) {
    $actions['mark_processing'] = __( 'ORDER PROCESSING', 'woocommerce' );
    $actions['mark_completed']  = __( 'PACKAGE DELIVERED', 'woocommerce' );

    return $actions;
}

function softworks_change_statuses_order( $wc_statuses_arr ){
 
  $new_statuses_arr = array(
    'wc-processing' => $wc_statuses_arr['wc-processing'], // 1
    'wc-package-collected' => $wc_statuses_arr['wc-package-collected'], // 2
    'wc-package-ontheway' => $wc_statuses_arr['wc-package-ontheway'], // 3
    'wc-completed' => $wc_statuses_arr['wc-completed'], // 4
    'wc-cancelled' => $wc_statuses_arr['wc-cancelled'], // 5
    'wc-refunded' => $wc_statuses_arr['wc-refunded'], // 6
    'wc-failed' => $wc_statuses_arr['wc-failed'], // 7
    'wc-pending' => $wc_statuses_arr['wc-pending'], // 8
    'wc-on-hold' => $wc_statuses_arr['wc-on-hold'] // 9
  );
 
  return $new_statuses_arr;
}
add_filter( 'wc_order_statuses', 'softworks_change_statuses_order' );

Custom Order Action in WooCommerce

The only specific thing you will need to take note of is to use the correct post_type. For WooCommerce orders you will need to use this in place of the first example on that tutorial:

add_action('admin_footer-edit.php', 'codeman_house_bulk_admin_footer');

function codeman_house_bulk_admin_footer() {

    global $post_type;

    if($post_type == 'shop_order') {
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function() {
            jQuery('<option>').val('export').text('<?php _e('Export')?>').appendTo("select[name='action']");
            jQuery('<option>').val('export').text('<?php _e('Export')?>').appendTo("select[name='action2']");
        });
    </script>
    <?php
    }
}

Orders are created in WooCommerce when a customer completes their checkout process. WooCommerce orders have different statuses. Which lets you know the current position of the order, whether it is complete or its payment is pending, etc. WooCommerce Order Status.
So, WooCommerce has few pre-defined order statuses which helps us to move the order from one stage to another in the processing cycle. Let’s have a look at them.