如何修改WooCommerce订单确认页订单概览中的Total标题?
修改WooCommerce订单收到页订单概览Total标题的方法
你可以通过WooCommerce原生提供的过滤器钩子实现需求,不需要修改核心或模板文件,有两种可选方案:
- 方案一(推荐):精准只修改订单收到页的Total标题
使用woocommerce_get_order_item_totals钩子,将以下代码添加到当前使用主题的functions.php文件,或者自定义代码片段插件中即可:
add_filter( 'woocommerce_get_order_item_totals', 'custom_order_received_total_label', 10, 3 ); function custom_order_received_total_label( $total_rows, $order, $tax_display ) { // 仅在订单收到页生效 if ( is_wc_endpoint_url( 'order-received' ) ) { // 此处引号内的文案可自定义修改 $total_rows['order_total']['label'] = '你想要替换的新标题:'; } return $total_rows; }
该方案优势是不会影响购物车、结算页、用户中心订单页的Total标题,完全匹配需求。
提示:建议优先使用子主题的functions.php文件添加代码,或者使用Code Snippets这类自定义代码插件,避免主题更新后自定义代码被覆盖。
- 方案二:全局修改所有页面的Total标题
如果需要把所有WooCommerce页面中出现的Total标题都替换,可以使用翻译钩子:
add_filter( 'gettext_woocommerce', 'rename_woocommerce_total_text', 10, 3 ); function rename_woocommerce_total_text( $translated, $original_text, $domain ) { if ( $original_text === 'Total' ) { $translated = '你想要替换的新标题'; } return $translated; }
需求对应的页面位置参考截图:
内容的提问来源于stack exchange,提问作者Shoroar
相关产品推荐
相关产品推荐

