Hi Daniel
I don’t think this string can be translated in the editor because it appears only when needed, but there are ways to translate strings using filters in JavaScript.
This documentation covers it: https://developer.wordpress.org/block-editor/reference-guides/filters/i18n-filters/#basic-example
I just tested this myself in the browser console and it worked:
function myPluginGettextFilter( translation, text, domain ) {
if ( text === 'No shipping options are available for this address. Please verify the address is correct or try a different address.' ) {
return 'This is your replacement text';
}
return translation;
}
wp.hooks.addFilter(
'i18n.gettext',
'my-plugin/override-add-to-reusable-blocks-label',
myPluginGettextFilter
);
Hope that helps.
Hi @mikejolley,
Thank you for answering. I’ve tried the JS snippet in my browser without any luck. We have the checkout in Spanish so the messages we need to translate are:
- “Añade una dirección de envío para ver las opciones de envío.”
- “No hay opciones de envío disponibles“
I’ve tried any string but nothing changes in the frontend:
function myPluginGettextFilter( translation, text, domain ) {
if ( text === 'No hay opciones de envío disponibles' ) {
return 'Some different text';
}
return translation;
}
// Adding the filter
wp.hooks.addFilter(
'i18n.gettext',
'my-plugin/override-add-to-reusable-blocks-label',
myPluginGettextFilter
);
Any ideas?
Thank you again.
Hi there!
I understand your concern. I tested the above code on my site, and it’s not working correctly either. However, I was able to successfully change the text using the Loco Translate plugin, as demonstrated in this screenshot: https://go.screenpal.com/watch/cZXr6AnVy6g.
Could you please try using the Loco Translate plugin to update the text? If you prefer not to use the plugin and want a code-based solution, please note that we don’t provide support for customizations.
If you need more in-depth support or want to consider professional assistance for customization, I can recommend WooExperts and Codeable.io as options for getting professional help. Alternatively, you can also ask your development questions in the WooCommerce Community Slack as custom code falls outside our usual scope of support.