You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除WooCommerce结果计数中的“showing”和“result”字样?

修改WooCommerce结果计数显示

要把WooCommerce默认的“showing 1–20 of 7225 results”改成“1–20 of 7225”,可以通过以下两种方法实现:

方法一:使用过滤器修改文本

在主题的functions.php文件(推荐用子主题,避免主题更新丢失代码)或自定义插件中添加以下代码:

add_filter( 'woocommerce_result_count', 'custom_woocommerce_result_count' );
function custom_woocommerce_result_count( $text ) {
    // 匹配默认格式并提取数字段
    preg_match('/(\d+)–(\d+) of (\d+) results/', $text, $matches);
    if ( isset($matches[1], $matches[2], $matches[3]) ) {
        return $matches[1] . '–' . $matches[2] . ' of ' . $matches[3];
    }
    return $text;
}

方法二:修改WooCommerce模板文件

如果你的主题已经重写了WooCommerce模板,找到主题目录下的woocommerce/loop/result-count.php文件,修改输出逻辑:
原核心输出代码大概是:

<p class="woocommerce-result-count">
    <?php
    if ( $total <= $per_page || $current_page === 1 ) {
        printf( _n( 'Showing the single result', 'Showing %1$d–%2$d of %3$d results', $total, 'woocommerce' ), $first, $last, $total );
    } else {
        printf( _nx( 'Showing the single result', 'Showing %1$d–%2$d of %3$d results', $total, 'result count', 'woocommerce' ), $first, $last, $total );
    }
    ?>
</p>

修改为:

<p class="woocommerce-result-count">
    <?php
    if ( $total <= $per_page || $current_page === 1 ) {
        printf( _n( '%d', '%1$d–%2$d of %3$d', $total, 'woocommerce' ), $first, $last, $total );
    } else {
        printf( _nx( '%d', '%1$d–%2$d of %3$d', $total, 'result count', 'woocommerce' ), $first, $last, $total );
    }
    ?>
</p>

注意

  • 不要直接修改WooCommerce核心文件,否则插件更新后修改会失效。
  • 使用子主题或自定义插件添加过滤器是更安全的长期方案。

内容的提问来源于stack exchange,提问作者Diana Hakobyan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 10:45:35