Created
September 4, 2021 21:08
-
-
Save warnakey/1059ba1a4b356086d2fa72173f883d9a to your computer and use it in GitHub Desktop.
If you want to change the text of WooCommerce notices
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- You can add this near the bottom of your footer.php --> | |
<!-- As an example, assume your checkout page had these 2 notifications by default --> | |
<!-- and you wanted to replace both of them: https://i.snipboard.io/MvmKWL.jpg --> | |
<?php if($post->ID == 353034) } /* Change this ID to match the ID of your checkout page */ ?> | |
<script> | |
var getAllWooMessages = document.getElementsByClassName("woocommerce-info"); | |
for (var i = 0; i < getAllWooMessages.length; i++) { | |
(function(x) { | |
var theinnerhtml = getAllWooMessages[x].innerHTML; | |
//console.log(theinnerhtml); // optional, if you want to check what the text is inside each notification | |
// Below here, you will enter in the text of the original WooCommerce notifications, one at a time | |
// You do not need to put in the entire text, for example, in #1 below, "Coupon added but not yet applied" would be enough to work | |
// Add as many of these as you need, but keep renaming the variables 'substring_3', 'substring_4', etc., as you add more | |
var substring_1 = "Coupon added but not yet applied:<br>Sorry, this coupon is not applicable to selected products."; | |
var substring_2 = "Your cart is currently empty."; | |
// In the code blocks below, as you copy them, replace 'substring_1', etc., so they match the variables you create above | |
if (theinnerhtml.includes(substring_1)) { | |
// Below here, between the double quotes, add in whatever text you want to replace the original message with (overwrite my example) | |
// Do the same for all of the code blocks below, including any you might make yourself | |
getAllWooMessages[x].innerHTML = "Your free gifts will be added once you add your shoes to your cart. Please select your shoes above to receive your $558.94 worth of free gifts!"; | |
} | |
if (theinnerhtml.includes(substring_2)) { | |
getAllWooMessages[x].innerHTML = "Your shopping cart is empty. Please add products to your cart to continue."; | |
} | |
}(i)) | |
} | |
</script> | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment