2

I want to replace a text on my Wordpress website enclosed in p tag as follows:

<div class="uael-mc-dropdown_items">
<p class="woocommerce-mini-cart__empty-message">No products in the cart.</p>
</div>

I want to replace the "No products in the cart." text with "No courses in my bag."

Is there any way to do so using js, CSS, or adding some code in my theme functions.php?

  • If the string is always `No products in the cart.` you could use `str_replace` pretty easily on that. I'm surprised the plug in doesnt have a setting for default text though – user3783243 Feb 13 '21 at 15:03
  • Maybe a good thread is https://wordpress.org/support/topic/change-the-no-products-in-the-cart-message/ – user3783243 Feb 13 '21 at 15:04
  • via CSS : https://stackoverflow.com/questions/7896402/how-can-i-replace-text-with-css , via js https://stackoverflow.com/questions/121817/how-do-i-replace-text-inside-a-div-element and for php do your own search here ;) – G-Cyrillus Feb 13 '21 at 15:05
  • ... via js, i'd go with texContent ;) – G-Cyrillus Feb 13 '21 at 15:24

3 Answers3

2

you can do this by using js, i added a timeout function that u see the difference, but u just need this one line inside the timeout function

setTimeout(()=>{
    document.querySelector('.woocommerce-mini-cart__empty-message').innerHTML = 'No courses in my bag';
},800)
<div class="uael-mc-dropdown_items">
<p class="woocommerce-mini-cart__empty-message">No products in the cart.</p>
</div>
1

You can use this script tag to override the content of the inner text as you mentioned

<body>
.
.
.
<script>
document.getElementsByClassName('woocommerce-mini-cart__empty- 
message').innerText ="No courses in my bag.";
</script>
</body>
  • It didn't work. This did. – Ankit Singh Rathore Feb 13 '21 at 16:03
0

You could use innerText attribute

Refer: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText