jquery - 在 WooCommerce 状态仪表板小部件中重命名单词
问题描述
我想在 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:");
});
});
有什么建议吗?
解决方案
我宁愿避免的解决方案,但这将是最快/最简单的解决方案之一。
使用 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' );
推荐阅读
- sql - 从 SQL 输出中获取特定的单词
- python - 如何在 pandas 中添加一个列,它是基于多个条件的一行的平均值
- mongodb - cosmos DB 收集订单问题
- swift - GameKit 实时多人游戏通过 GKMatchmakerViewController 连接失败
- python-xarray - 将 xarray 重新采样到更高的空间分辨率
- javascript - Ajax 调用不将数据附加到 tfoot 元素(但在 thead 元素中正常工作)?
- javascript - 从另一个中间件获取结果返回未定义
- python - 如何“展平” Pandas 数据框?
- react-native - 视频在平面列表中加载太耗时
- vscode-extensions - 如何在 vscode 扩展中检索现有的输出通道?