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;
}