【问题标题】:Renaming words in WooCommerce status dashboard widget在 WooCommerce 状态仪表板小部件中重命名单词
【发布时间】:2021-06-30 08:19:51
【问题描述】:

我想重命名 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;
}


我也试过这个,但结果并不好。它不仅会覆盖文本,还会覆盖用于链接的 HTML。

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

有什么建议吗?

【问题讨论】:

  • 也许这些词不是通过一开始的国际化函数输出的?
  • 您想在此处更改主题,还是在整个网站上更改主题?
  • 这些看起来像订单状态 - 也许您想重命名它们? stackoverflow.com/questions/37790855/…
  • 我觉得你需要改一下具体订单状态的名称
  • @ВладимирКятипов 这是一个“肮脏的解决方案”,但在这种情况下使用 jQuery 有时会提供快速解决方案

标签: jquery wordpress woocommerce widget backend


【解决方案1】:

我宁愿避免的解决方案,但这将是最快/最简单的解决方案之一。

使用 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' );

【讨论】:

  • 我想知道,在哪里可以看到类似的jQuery函数并了解更多?在类似的情况下,它们非常“好”。
猜你喜欢
  • 2017-12-21
  • 1970-01-01
  • 2016-10-13
  • 1970-01-01
  • 1970-01-01
  • 2017-01-18
  • 1970-01-01
  • 2014-04-02
  • 1970-01-01
相关资源
最近更新 更多