How to Change Cart Totals Text on WooCommerce Cart Page?

In this article, I’ll share a bit of code to help you customize the cart total text on the WooCommerce cart page.

So without any further ado, let’s jump into the tutorial. 

Change Cart Totals Text on WooCommerce Cart Page

Besides changing the total cart text on the WooCommerce cart page, you can also change the ‘Shipping’ and ‘Subtotal’ labels. 

Follow the following steps to change the total cart text on the WooCommerce cart page

1. Code to Change the Cart Totals text on WooCommerce Cart Page

I’ll use the code to change the cart total text on the WooCommerce cart page. Copy the following code to do so. 

function woosuite_change_cart_totals_text( $translated_text, $text, $domain ) {
    if ( $text === 'Total' ) {
        $translated_text = 'Your New Text';
    }
    return $translated_text;
}
add_filter( 'gettext', 'woosuite_change_cart_totals_text', 20, 3 );

2. Understanding the Code

Here, I’ll explain the code to give you a better understanding. 

  • The function is defined with the name woosuite_change_cart_totals_text. It takes three parameters: $translated_text, $text, and $domain.
  • Inside the function is an if statement that checks if the value of $text equals ‘Total’.
  • If the condition is true, the variable $translated_text is assigned the value ‘Your New Text’. This means that whenever the original text “Total” is encountered, it will be replaced with the custom text specified.
  • Finally, the function returns the modified $translated_text value.
  • The add_filter() function is used to hook the woosuite_change_cart_totals_text function to the gettext filter with a priority of 20. This ensures that the custom text replacement takes place appropriately during the translation

3. Paste the Code to Your Store

After copying the code, we need to paste it into the WooCommerce store to change the cart totals text on the WooCommerce cart page. 

We have shared a few ways to add the code to WordPress here.

I have used a code snippet plugin to paste the code to my demo store. 

Don’t forget to save and activate the snippet. 

4. Final Results

Here are the final results after pasting the above code to my store. 

Change Shipping Text on WooCommerce Cart Page

You need to use the following code to change the shipping text label on the WooCommerce cart page. 

function woosuite_change_shipping_label( $label ) {
    $new_label = 'Delivery Charges';
    return $new_label;
}
add_filter( 'woocommerce_shipping_package_name', 'woosuite_change_shipping_label' );

Final Results

Here are the final results after pasting the above code to my store. 

Change Subtotal Text on WooCommerce Cart Page

You need to use the following code to change the subtotal text label on the WooCommerce cart page.

function woosuite_change_subtotals_text( $translated_text, $text, $domain ) {
    if ( $text === 'Subtotal' ) {
        $translated_text = 'Your New Label';
    }
    return $translated_text;
}
add_filter( 'gettext', 'woosuite_change_subtotals_text', 20, 3 );

Final Results

Here are the final results after pasting the above code to my store. 

Conclusion

I hope this article was helpful to you and you were able to change the cart totals text on the WooCommerce cart page. I have also shared the code to change the ‘Shipping’ and ‘Subtotal’ labels.  

Brian
Brian

Welcome to the AovUp blog, where we discuss all things WooCommerce. I hope we can help you achieve something today...

Leave a Reply

Your email address will not be published. Required fields are marked *

We – and our partners – use cookies to deliver our services and to show you ads. By using our website, you agree to the use of cookies as described in our Cookie Policy