NO BUG: Update card text from {woo_cart_update} not changing

Hi,

I’m using this function to change the update button text

add_filter('gettext', 'change_update_cart_text', 20, 3);
function change_update_cart_text($translated_text, $text, $domain) {
    if ($domain === 'woocommerce') {
        switch ($translated_text) {
            case 'Update cart':
                if (ICL_LANGUAGE_CODE == 'es') {
                    return 'Actualizar';
                } elseif (ICL_LANGUAGE_CODE == 'en') {
                    return 'Update ';
                }
                break;
        }
    }
    return $translated_text;
}

I can see it working on the editor:

But not on the frontend

Hi @marcorubiol,

In your code, you’re checking for the text “Update cart” in English. However, when WooCommerce switches to Spanish, the string you’re trying to translate is likely already “Actualizar” or another Spanish equivalent. This means your logic won’t trigger for the Spanish language, and the button text won’t be updated as you expect.

To handle this correctly, you should account for the existing Spanish string in your logic. Here’s how your code should look (use the actual Spanish string if it’s not ‘Actualizar’):

add_filter( 'gettext', 'change_update_cart_text', 20, 3 );
function change_update_cart_text( $translated_text, $text, $domain ) {
	if ( $domain === 'woocommerce' ) {
		switch ( $translated_text ) {
			case 'Update cart': // English
				return 'Update'; // Desired English text
			case 'Actualizar': // Existing Spanish string
				return 'Actualizar'; // Desired Spanish text
		}
	}

	return $translated_text;
}

You’re right. Thank you for your help!

1 Like