Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change cart totals title text on cart page in Woocommerce

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

like image 330
Donny Dug Avatar asked Aug 25 '18 03:08

Donny Dug


1 Answers

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

like image 56
LoicTheAztec Avatar answered Sep 22 '22 02:09

LoicTheAztec