How To Create Custom Order Status in WooCommerce

In this article i will show you how to create custom order status in WooCommerce. you just need to add below snippet in functions.php.

WooCommerce Order Status(Built-in)

  • Payment Pending
  • Processing
  • On Hold
  • Completed
  • Cancelled
  • Refunded
  • Failed


/**
* Register new status : Partially refunded
* https://www.zorem.com/how-to-create-custom-order-status-in-woocommerce/
**/
function register_shipment_arrival_order_status() {
register_post_status( 'wc-partially-refund', array(
'label'                     => 'Partially refunded',
'public'                    => true,
'show_in_admin_status_list' => true,
'show_in_admin_all_list'    => true,
'exclude_from_search'       => false,
'label_count'               => _n_noop( 'Partially refunded (%s)', 'Partially refunded (%s)' )
) );
}
add_action( 'init', 'register_shipment_arrival_order_status' );

function add_awaiting_shipment_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-partially-refund'] = 'Partially refunded';
}
}

return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_awaiting_shipment_to_order_statuses' );

This snippate will add custom order status Partially refunded.

Leave a Reply

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