How To Add, Remove Or Change Order Of WooCommerce Statuses

Here we learn about how to add, remove or change order of WooCommerce statuses.

wc_order_statuses :

This filter hook allows adding, remove or change the order of WooCommerce statuses.

Custom code copied and paste into your child theme’s functions.php file.

1. Removing Core Order Statuses :

If you do not refunds via website, you may turn off ‘Refunded’ status.

Example:

<?php
function myblog_remove_order_statuses( $wc_statuses_arr ){
  // Processing
  if( isset( $wc_statuses_arr['wc-processing'] ) ) { // if exists
    unset( $wc_statuses_arr['wc-processing'] ); // remove it from array
  }
  // Refunded
  if( isset( $wc_statuses_arr['wc-refunded'] ) ){
    unset( $wc_statuses_arr['wc-refunded'] );
  }
  // On Hold
  if( isset( $wc_statuses_arr['wc-on-hold'] ) ){
    unset( $wc_statuses_arr['wc-on-hold'] );
  }
  // Failed
  if( isset( $wc_statuses_arr['wc-failed'] ) ){
    unset( $wc_statuses_arr['wc-failed'] );
  }
  // Pending payment
  if( isset( $wc_statuses_arr['wc-pending'] ) ){
    unset( $wc_statuses_arr['wc-pending'] );
  }
  // Completed
  //if( isset( $wc_statuses_arr['wc-completed'] ) ){
  //    unset( $wc_statuses_arr['wc-completed'] );
  //}
  // Cancelled
  //if( isset( $wc_statuses_arr['wc-cancelled'] ) ){
  //    unset( $wc_statuses_arr['wc-cancelled'] );
  //}
  return $wc_statuses_arr; // return result statuses
}
add_filter( 'wc_order_statuses', 'myblog_remove_order_statuses' );
?>	

After using this code, you can see the result on the order page in the admin area:

2. Custom Order Statuses :

If you Register new status with ID ‘wc-my-shipment’ and label ‘Waiting shipment’.

Example:

<?php	
function myblog_register_awaiting_shipment_status() {

  register_post_status( 'wc-my-shipment', array(
    'label'		=> 'Waiting shipment',
    'public'	=> true,
    'show_in_admin_status_list' => true, // show count All (12) , Completed (9) , Awaiting shipment (2) ...
    'label_count'	=> _n_noop( 'Waiting shipment <span class="count">(%s)</span>', 'Waiting shipment <span class="count">(%s)</span>' )
  ) );
 
}
add_action( 'init', 'myblog_register_awaiting_shipment_status' );
 
/*
 * Add registered status to list of WC Order statuses	 
 */
function my_add_status( $wc_statuses_arr ) {
 
  $new_statuses_arr = array();
 
  // add new order status after processing
  foreach ( $wc_statuses_arr as $id => $label ) {
    $new_statuses_arr[ $id ] = $label;
 
    if ( 'wc-completed' === $id ) { // after "Completed" status
      $new_statuses_arr['wc-my-shipment'] = 'Waiting shipment';
    }
  }
 
  return $new_statuses_arr;
 
  // if order status order doesn't matter for you you can remove lines 21-32 and uncomment the following 35-36
  // $wc_statuses_arr['wc-my-shipment'] = 'Waiting shipment';
  // return $wc_statuses_arr;
 
}
add_filter( 'wc_order_statuses', 'my_add_status' );
?>

 

3. Change Order Statuses Order :

If you Change statuses order in a dropdown list.

<?php	
function myblog_change_statuses_order( $wc_statuses_arr ){	 
  $my_statuses_arr = array(
    'wc-processing' => $wc_statuses_arr['wc-processing'], // 1
    'wc-completed' => $wc_statuses_arr['wc-completed'], // 2
    'wc-cancelled' => $wc_statuses_arr['wc-cancelled'], // 3
    'wc-refunded' => $wc_statuses_arr['wc-refunded'], // 4
    'wc-failed' => $wc_statuses_arr['wc-failed'], // 5
    'wc-pending' => $wc_statuses_arr['wc-pending'], // 6
    'wc-on-hold' => $wc_statuses_arr['wc-on-hold'] // 7
  );	 
  return $my_statuses_arr;
}	 
add_filter( 'wc_order_statuses', 'myblog_change_statuses_order' );
?>

 

 

Submit a Comment

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

Subscribe

Select Categories