7

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>';                                                
}

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.

Any advice would be appreciated.

Default Cart Totals Example

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Donny Dug
  • 73
  • 1
  • 1
  • 7
  • Hi Donny Dug, WooCommerce not provided any Hook to change cart totals text.. Either you can hide this text through css. or you need to change text in WooCommerce Cart Page template file.. – Yogesh Garg Aug 25 '18 at 04:26
  • Yes, thats the issue, however Loics answer worked perfectly! – Donny Dug Aug 27 '18 at 00:23

3 Answers3

15

It is possible using the WordPress filter hook gettext.

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) 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;
}

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

Or you can remove it from the Woocommerce template cart/cart_totals.php

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
3
function change_cart_totals($translated){
  $translated = str_ireplace('Cart Totals', 'Cart Total', $translated);
  return $translated;
}
add_filter('gettext', 'change_cart_totals' );
lczapski
  • 4,026
  • 3
  • 16
  • 32
  • Code-only answers are generally frowned upon on this site. Could you please edit your answer to include some comments or explanation of your code? Explanations should answer questions like: What does it do? How does it do it? Where does it go? How does it solve OP's problem? See: [How to anwser](https://stackoverflow.com/help/how-to-answer). Thanks! – Eduardo Baitello Nov 21 '19 at 14:07
-1

Duplicate the cart-totals.php theme from woocommerce into your own theme, and replace this line:

<h2><?php esc_html_e( 'Cart totals', 'woocommerce' ); ?></h2>