2

I need to rename "On Hold" to "Pending Approval" and "Processing" to "Approved", in every instance. (Btw, I'm a diy shop owner, not a developer)

This topic got me 60% there, Rename multiple order statuses in Woocommerce Now need to address these locations:

  • admin > orders, the preview popup (eye symbol).
  • front end > my-account/orders, the Status column.
  • front end > my-account/view-order/x, the summary line.

My code:

add_filter( 'wc_order_statuses', 'rename_order_statuses', 20, 1 );
function rename_order_statuses( $order_statuses ) {
    $order_statuses['wc-processing'] = _x( 'Approved', 'Order status', 'woocommerce' );
    $order_statuses['wc-on-hold']    = _x( 'Pending Approval', 'Order status', 'woocommerce' );

    return $order_statuses;
}
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 Approved', 'woocommerce' );
    $actions['mark_on-hold']    = __( 'Mark Pending Approval', 'woocommerce' );

    return $actions;
}

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-processing'] ) )
        $views['wc-processing'] = str_replace( 'Processing', __( 'Approved', 'woocommerce'), $views['wc-processing'] );

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

    return $views;
}
LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Scott
  • 55
  • 3
  • 6

1 Answers1

2

Your code made from Rename multiple order statuses in Woocommerce answer code already cover everything (90%), including:

Front end > my-account/orders, the Status column.

enter image description here

Front end > my-account/view-order/x, the summary line

enter image description here

Otherwise, if it doesn't work, it could be caused by other customizations from you theme, a plugin or your own customizations.


Now to handle Admin > orders, the preview popup (eye symbol) use the following code:

add_filter( 'woocommerce_admin_order_preview_actions', 'filter_admin_order_preview_actions', 10, 2 );
function filter_admin_order_preview_actions( $actions, $order ) {
    $actions        = array();
    $status_actions = array();

    if ( $order->has_status( array( 'pending' ) ) ) {
        $status_actions['on-hold'] = array(
            'url'    => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=on-hold&order_id=' . $order->get_id() ), 'woocommerce-mark-order-status' ),
            'name'   => __( 'On-hold', 'woocommerce' ),
            'title'  => __( 'Change order status to on-hold', 'woocommerce' ),
            'action' => 'on-hold',
        );
    }
    if ( $order->has_status( array( 'pending', 'on-hold' ) ) ) {
        $status_actions['processing'] = array(
            'url'    => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=processing&order_id=' . $order->get_id() ), 'woocommerce-mark-order-status' ),
            'name'   => __( 'Approved', 'woocommerce' ),
            'title'  => __( 'Change order status to approved', 'woocommerce' ),
            'action' => 'processing',
        );
    }

    if ( $order->has_status( array( 'pending', 'on-hold', 'processing' ) ) ) {
        $status_actions['complete'] = array(
            'url'    => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=completed&order_id=' . $order->get_id() ), 'woocommerce-mark-order-status' ),
            'name'   => __( 'Completed', 'woocommerce' ),
            'title'  => __( 'Change order status to completed', 'woocommerce' ),
            'action' => 'complete',
        );
    }

    if ( $status_actions ) {
        $actions['status'] = array(
            'group'   => __( 'Change status: ', 'woocommerce' ),
            'actions' => $status_actions,
        );
    }
    return $actions;
}

And to rename the status on Admin order list button when hovered:

add_filter( 'woocommerce_admin_order_actions', 'rename_admin_order_status_action_button', 10, 2 );
function rename_admin_order_status_action_button( $actions, $order ) {
    // Display the button for all orders that have a 'processing', 'pending' or 'on-hold' status
    if ( isset($actions['processing']) ) {
        $actions['processing']['name'] = __( 'Approved', 'woocommerce');
    }

    return $actions;
}

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

enter image description here

enter image description here

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • Thanks Loic for the new code, and for demonstrating that my code was working in the front end. Unfortunately I cannot produce same results. Disabled every plugin and customization, one by one. Running StoreFront theme. Up to date on theme, Woo, and Wordpress. The only outdated component is PHP 5.6 on this server. Could that have anything to do with it? – Scott Jan 21 '19 at 22:51
  • @Scott For testing I use the same thing than you: Storefront + Woocommerce 3.5.4 *(Php version has no effect in here)*. Your first function code renames the related order status in front end. So there is something else that is interacting in your case… Check that the templates are up to date in backend > Woocommerce > status *(at the end of the page: "Template overrides")*. – LoicTheAztec Jan 21 '19 at 23:53
  • Thanks again. I finally realized the problem...I am using a PHP snippets plugin instead of a child theme this time, and I had the snippet set to run only in admin. Changed it to run everywhere, problem solved! Rookie mistake. The only place the original names are showing now is when hovering on a status in Admin>Orders list. But I can live with that. – Scott Jan 22 '19 at 20:28
  • @Scott You say *"The only place the original names are showing now is when hovering on a status in Admin>Orders list…"* I have added some code to handdle that too… check it. – LoicTheAztec Jan 22 '19 at 20:50