在Woocommerce中更改购物车页面上购物车总标题文本 [英] Change cart totals title text on cart page in Woocommerce

查看:172
本文介绍了在Woocommerce中更改购物车页面上购物车总标题文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在WooCommerce中更改购物车总计div中的文本购物车总计",或通过操作将其完全删除.

I'm looking to change the text "Cart Totals" in the cart totals div in WooCommerce or remove it totally with an action.

我在使用中在框上方添加了不同的文本

I've added different text above the box in using

add_action( 'woocommerce_before_cart_totals', 'custom_before_cart_totals' );
function custom_before_cart_totals() {
        echo '<h2>Checkout</h2>';                                                
}

但是,除了编辑WooCommerce模板或目标并使用CSS隐藏之外,我找不到其他方法来删除默认的购物车总计"字样,但是我喜欢我可以在函数文件中放置的内容,以更改旧文本或完全删除它.

But I cant find a way to remove the default wording "Cart Totals" other than editing a WooCommerce template or target and hiding with css, but would love something that I can place in the functions file to either change the old text or remove it completely.

任何建议将不胜感激.

默认购物车总计示例

推荐答案

可以使用WordPress过滤器挂钩gettext.

It is possible using the WordPress filter hook gettext.

1)删除购物车总计":

1) Removing "Cart totals":

add_filter( 'gettext', 'change_cart_totals_text', 20, 3 );
function change_cart_totals_text( $translated, $text, $domain ) {
    if( is_cart() && $translated == 'Cart totals' ){
        $translated = '';
    }
    return $translated;
}

2)替换(或更改)购物车总计":

2) Replace (or change) "Cart totals":

add_filter( 'gettext', 'change_cart_totals_text', 20, 3 );
function change_cart_totals_text( $translated, $text, $domain ) {
    if( is_cart() && $translated == 'Cart totals' ){
        $translated = __('Your custom text', 'woocommerce');
    }
    return $translated;
}

代码进入您的活动子主题(或活动主题)的function.php文件中.经过测试,可以正常工作.

Code goes in function.php file of your active child theme (or active theme). Tested and works.

或者您可以将其从Woocommerce模板cart/cart_totals.php

这篇关于在Woocommerce中更改购物车页面上购物车总标题文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆