5

I'm trying to rename multiple WooCommerce order status by editing my theme's functions.php file. I found some code posted here a couple years ago that works to change a single order status, but since I'm very inexperienced with php, I don't know how to expand on it to change multiple statuses. Ideally I'd also like to rename 'wc-processing' to 'Paid' and 'wc-on-hold' to 'Pending'.

Here's the code I found to edit a single order status:

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

Anyone know what changes I need to make to change additional statuses?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
beth
  • 53
  • 1
  • 6

1 Answers1

19

As Pending order status exist, you need also to rename the existing "Pending" status. If not you will get 2 different statuses with the same "Pending" label.

First to rename those order statuses:

add_filter( 'wc_order_statuses', 'rename_order_statuses', 20, 1 );
function rename_order_statuses( $order_statuses ) {
    $order_statuses['wc-completed']  = _x( 'Order Received', 'Order status', 'woocommerce' );
    $order_statuses['wc-processing'] = _x( 'Paid', 'Order status', 'woocommerce' );
    $order_statuses['wc-on-hold']    = _x( 'Pending', 'Order status', 'woocommerce' );
    $order_statuses['wc-pending']    = _x( 'Waiting', 'Order status', 'woocommerce' );

    return $order_statuses;
}

And Also in the bulk edit order list dropdown:

add_filter( 'bulk_actions-edit-shop_order', 'custom_dropdown_bulk_actions_shop_order', 20, 1 );
function custom_dropdown_bulk_actions_shop_order( $actions ) {
    $actions['mark_processing'] = __( 'Mark paid', 'woocommerce' );
    $actions['mark_on-hold']    = __( 'Mark pending', 'woocommerce' );
    $actions['mark_completed']  = __( 'Mark order received', 'woocommerce' );

    return $actions;
}

enter image description here

And also this is needed (for the top menu):

foreach( array( 'post', 'shop_order' ) as $hook )
    add_filter( "views_edit-$hook", 'shop_order_modified_views' );

function shop_order_modified_views( $views ){
    if( isset( $views['wc-completed'] ) )
        $views['wc-completed'] = str_replace( 'Completed', __( 'Order Received', 'woocommerce'), $views['wc-completed'] );

    if( isset( $views['wc-processing'] ) )
        $views['wc-processing'] = str_replace( 'Processing', __( 'Paid', 'woocommerce'), $views['wc-processing'] );

    if( isset( $views['wc-on-hold'] ) )
        $views['wc-on-hold'] = str_replace( 'On hold', __( 'Pending', 'woocommerce'), $views['wc-on-hold'] );

    if( isset( $views['wc-pending'] ) )
        $views['wc-pending'] = str_replace( 'Pending', __( 'Stucked', 'woocommerce'), $views['wc-pending'] );

    return $views;
}

(Thanks to brasofilo : Change WP admin post status filter for custom post type)

enter image description here

Code goes in function.php file of your active child theme (or active theme). Tested and works.

Since Woocommerce 3.3 to handle the preview popup (eye symbol) in admin order list:

Replace order status names everywhere incl. Woocommerce admin order preview

Community
  • 1
  • 1
LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • This works really well. However if the string has been translated, the "sub menu" (ul.subsubsub) uses the translated string instead of the newly assigned string. – InanisAtheos Oct 17 '19 at 11:37
  • @PatrikAlienus This depends on many things (like if when use a plugin for translations)… – LoicTheAztec Oct 17 '19 at 16:21
  • I'm not using a plugin for translating it, just the .mo files in the language directory. – InanisAtheos Oct 23 '19 at 07:03
  • @PatrikAlienus you can try by increasing the hook priority like: `add_filter( "views_edit-$hook", 'shop_order_modified_views', 1000 );` – LoicTheAztec Oct 23 '19 at 07:48
  • @LoicTheAztec Everything works fine for me except the code for the top menu. I have woocommerce 6.8. Maybe something has changed? – Nerea Sep 04 '22 at 21:24