Friday , February 7 2025

How to change text for Add to Cart button for Woocommerce

This task can be solved by editing the translation files of your theme. But you can use a hook that allows you to rename the “Add to Cart” button faster. In the file functions.php add the following code:

add_filter( 'woocommerce_product_single_add_to_cart_text', 'tb_woo_custom_cart_button_text' );
add_filter( 'woocommerce_product_add_to_cart_text', 'tb_woo_custom_cart_button_text' );   
function tb_woo_custom_cart_button_text() {
        return __( 'Buy!', 'woocommerce' );
}

The word “Buy!” in this example can be changed to any word, but do not touch the quotes.

Change phrases View cart, Update cart, Checkout

Use the following code:

function tb_text_strings( $translated_text, $text, $domain ) {
    switch ( $translated_text ) {
        case 'View cart' :
            $translated_text = __( 'Go to your shopping cart', 'woocommerce' );
            break;
        case 'Update cart' :
            $translated_text = __( 'Refresh your shopping cart', 'woocommerce' );
            break;
        case 'Checkout' :
            $translated_text = __( 'Finish your order', 'woocommerce' );
            break;
    }
    return $translated_text;
}
add_filter( 'gettext', 'tb_text_strings', 20, 3 );

About iryna

I'm Iryna, a web developer from Ukraine with a decade of experience solving complex technical challenges in the world of freelance. Throughout my career, I've worked on everything from troubleshooting server-side issues and optimizing website performance to enhancing user interfaces. On this blog, I share detailed solutions to the technical problems I’ve encountered and methods that have worked best for me. In addition to my technical expertise, I’m also passionate about digital drawing. I hope the tutorials and insights I provide here will help both fellow developers and creatives alike in their own projects.

Check Also

Css styles for WordPress admin in functions.php

If you need to add individual styles, and they are only a couple of lines, …

Leave a Reply

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