在 Woocommerce 的购物车页面上更改购物车总计标题文本

Don*_*Dug 5 php wordpress cart woocommerce hook-woocommerce

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

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

add_action( 'woocommerce_before_cart_totals', 'custom_before_cart_totals' );
function custom_before_cart_totals() {
        echo '<h2>Checkout</h2>';                                                
}
Run Code Online (Sandbox Code Playgroud)

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

任何意见,将不胜感激。

默认购物车总计示例

Loi*_*tec 12

可以使用 WordPress 过滤器钩子gettext

1)删除“购物车总数”:

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;
}
Run Code Online (Sandbox Code Playgroud)

2) 替换(或更改) “购物车总数”:

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;
}
Run Code Online (Sandbox Code Playgroud)

代码位于活动子主题(或活动主题)的 function.php 文件中。测试和工作。

或者您可以从 Woocommerce 模板中删除它 cart/cart_totals.php