I’m experiencing an issue with changing an error message during the checkout process on my Shopify store. Specifically, I want to change the “Shipping not available for selected address” message to “Shipping not available for this product.”
Here are the steps I’ve taken so far:
-
I went to Online Store > Themes > Edit Default Theme Content and changed the relevant error message in the default language file.
-
I also tried adding custom JavaScript in the theme.liquid file to intercept and change the error message dynamically. Here’s a snippet of the code I used:
document.addEventListener(‘DOMContentLoaded’, function() {
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type === ‘childList’ && mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach(function(node) {
if (node.nodeType === 1 && node.classList.contains(‘errors’)) {
node.style.display = ‘none’;
}
});
} else if (mutation.type === ‘characterData’) {
var node = mutation.target;
if (node.nodeType === 3 && node.textContent.includes(‘Shipping not available for selected address’)) {
node.parentElement.style.display = ‘none’;
}
}
});
});
var config = { childList: true, subtree: true, characterData: true };
observer.observe(document.body, config);
// Hide the original error message persistently
setInterval(function() {
var errorMessages = document.querySelectorAll(‘.errors’);
errorMessages.forEach(function(errorMessage) {
if (errorMessage.innerText.includes(‘Shipping not available for selected address’)) {
errorMessage.style.display = ‘none’;
}
});
}, 100); // Check every 100ms
});
Despite these efforts, the message still intermittently reverts to the original “Shipping not available for selected address” when I switch between addresses at checkout.
Can anyone provide guidance on what I might be missing or suggest another way to ensure the custom error message remains consistent? I suspect there might be other language settings or theme customizations that I need to adjust, but I’m not sure where to look next.
Any help would be greatly appreciated!
Thank you in advance!