Home > OS >  Effect of renaming the WooCommerce Order Status
Effect of renaming the WooCommerce Order Status

Time:04-28

I have renamed the WooCommerce order status using the following code and it works fine. Here 'On hold' status is changed to 'Order Received'.

add_filter( 'wc_order_statuses', 'wc_renaming_order_status' );
function wc_renaming_order_status( $order_statuses ) {
    foreach ( $order_statuses as $key => $status ) {
        if ( 'wc-completed' === $key ) 
            $order_statuses['wc-on-hold'] = _x( 'Order Received', 'Order status', 'woocommerce' );
    }
    return $order_statuses;
}

Now the question is in my exiting codebase, in many places 'on-hold' status is being used, for example :


$order->update_status( apply_filters(
       'woocommerce_cod_process_payment_order_status',
       $order->has_downloadable_item() ? 'on-hold' : 'processing', $order
       ), __( 'Payment to be made upon delivery.', 'woocommerce' ) );

if($order->has_status('on-hold')) {
                   // do some operation
               }

Do I need to replace all occurrence of 'on-hold' with 'order-received' status or it will be automatically taken care by 'wc_order_statuses' filter ?

Thanks !!!

CodePudding user response:

By using the below code you can change the order status and order status label.

add_filter('wc_order_statuses', 'wc_renaming_order_status');

function wc_renaming_order_status($order_statuses) {

    $order_statuses['wc-on-hold'] = _x('Order Received', 'Order status', 'woocommerce');
    
    return $order_statuses;
}

Here the label of the order status is getting changed. It will not affect in any case where the status code ( on-hold, completed,...) is used.

See the attached screenshots of the applied and tested OK. enter image description here

enter image description here

  • Related