1

I would like renaming words in WooCommerce status dashboard widget (see screenshot).

I use the following code and it works well for the title of the widget, but not for the marked words. What can be reason for that?

add_filter(  'gettext',  'change_add_to_cart_message22', 10, 3 );
function change_add_to_cart_message22( $translated, $text, $domain  ) {
    global $pagenow;
    if( $text === 'on-hold' && $domain === 'woocommerce' && is_admin() && $pagenow === 'index.php' ){
        $translated = __( 'test', $domain );
    }
    return $translated;
}

enter image description here


I also tried this, but the result it's not good. It overwrites not only the text but also the HTML used for the link.

jQuery( document ).ready(function() {
    jQuery("#woocommerce_dashboard_status .wc_status_list li.processing-orders").text(function () {
       return jQuery(this).text().replace("awaiting", "Websites:"); 
    });
});

enter image description here

Any advice?

7uc1f3r
  • 25,125
  • 15
  • 25
  • 45
  • Maybe those words aren’t output via one of the internationalization functions to begin with? – CBroe Jun 30 '21 at 08:22
  • Do you want to change theme just here, or throughout the website ? – bhanu Jun 30 '21 at 08:23
  • These look like the order statuses - maybe you want to rename those? https://stackoverflow.com/questions/37790855/renaming-woocommerce-order-status – CBroe Jun 30 '21 at 08:24
  • I think you need to change the name of the specific order status instead – Mr. Jo Jun 30 '21 at 08:58
  • Strange is that I already tried to rename order statuses. Unfortunatelly, no worked. I look at code at see they are "hardcoded", so now I am thinking for way to override widget. [link](https://prnt.sc/17n17qo) – Vladimir Kyatipov Jun 30 '21 at 10:51
  • 1
    @ВладимирКятипов it's a 'dirty solution' but using jQuery sometimes offers the quick solution in these kinds of situations – 7uc1f3r Jun 30 '21 at 12:00
  • @7uc1f3r I tried, but seems div inside gots broken. I updated my question, can you take one look if you want? – Vladimir Kyatipov Jun 30 '21 at 14:41

1 Answers1

1

A solution I'd rather avoid, but this will be one of the quickest/easiest solutions.

Use jQuery. Make sure that the text you want to replace completely matches. For example, if this has already been translated, you should also apply it like this

So you get:

// Prints scripts or data before the default footer scripts.
// This hook is for admin only and can’t be used to add anything on the front end.
function action_admin_footer() {
    ?>
    <script>
        jQuery(document).ready(function($) {
            $( 'ul.wc_status_list .processing-orders a' ).html( function( index, text ) {
                return text.replace( 'awaiting processing', 'first new text' );
            });
            
            $( 'ul.wc_status_list .on-hold-orders a' ).html( function( index, text ) {
                return text.replace( 'on-hold', 'second new text' );
            });
        });
    </script>
    <?php
}
add_action( 'admin_footer', 'action_admin_footer' );
7uc1f3r
  • 25,125
  • 15
  • 25
  • 45