重命名 WooCommerce 状态仪表板小部件中的单词

Renaming words in WooCommerce status dashboard widget

我想重命名 WooCommerce 状态仪表板小部件中的单词(见屏幕截图)。

我使用以下代码,它适用于小部件的标题,但不适用于标记的单词。这可能是什么原因?

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;
}


这个我也试过了,但是效果不好。它不仅会覆盖文本,还会覆盖用于 link.

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

有什么建议吗?

我宁愿避免的解决方案,但这将是 quickest/easiest 解决方案之一。

使用jQuery。确保您要替换的文本完全匹配。比如这个已经翻译过了,你也应该这样应用

所以你得到:

// 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' );