Search code examples
phpwordpresswoocommercecartgettext

How to change the text from buttons in woocommerce mini cart


I'm trying to change the 'View cart' and "Checkout" buttons text in WooCommerce mini cart and make it "request quote" and maybe remove the 'view cart' button.

I tried a lot of solutions, first with CSS I tried to hide it or change the content attribute, and I tried the following:

add_filter( 'gettext', function( $translated_text ) {
    if ( 'View cart' === $translated_text ) {
        $translated_text = 'Your new text here';
    }
    return $translated_text;
} );

But it seems none of them worked for me.


Solution

  • There are some mistakes in your code. Try the following instead (emptying your cart first):

    add_filter( 'gettext', function( $translated_text, $original_text, $domain ) {
        // Not in cart or checkout pages
        if( is_cart() || is_checkout() ) {
            return $translated_text;
        }
    
        if ( 'View cart' === $original_text ) {
            $translated_text = 'Your new cart text';
        } 
        if ( 'Checkout' === $original_text ) {
            $translated_text = 'Your new chackout text';
        }
        return $translated_text;
    }, 10, 3 );
    

    Code goes in functions.php file of your child theme (or in a plugin). Tested and works.


    To remove mini cart "View cart" button, use:

    add_action( 'woocommerce_widget_shopping_cart_buttons', function(){
        // Removing Button
        remove_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_button_view_cart', 10 );
    }, 1 );
    

    To remove mini cart "Checkout" button, use:

    add_action( 'woocommerce_widget_shopping_cart_buttons', function(){
        // Removing Button
        remove_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_proceed_to_checkout', 20 );
    }, 1 );
    

    To customize mini cart buttons, see this thread

    Note: Always empty your cart, to refresh mini cart persistent display.