0

I want to change the add to cart button text, when a product is successfully added to the cart. I want to add soms custom html (a icon) to the button.

I tried to change the following, but that does not work. It does not read the HTMl but add it as plain text.

How can I solve this?

File: /app/design/frontend/Theme/theme/Magento_Catalog/web/js/catalog-add-to-cart.js

setTimeout(function () {
 var addToCartButtonTextDefault = self.options.addToCartButtonTextDefault || $t('<i class="fad fa-shopping-cart"></i>Add to Cart');
 addToCartButton.removeClass(self.options.addToCartButtonDisabledClass);
 addToCartButton.find('span').text(addToCartButtonTextDefault);
 addToCartButton.attr('title', addToCartButtonTextDefault);
}, 1000);
asked Dec 28, 2019 at 19:14
1
  • Answer posted check and let me know working or not Commented Dec 29, 2019 at 12:04

1 Answer 1

3

You just need to replace text() function to html() function

setTimeout(function () {
 var addToCartButtonTextDefault = self.options.addToCartButtonTextDefault || $t('<i class="fa fa-shopping-cart"></i>Add to Cart'); //add class fa fa-shopping-cart instead of fad fa-shopping-cart 
 addToCartButton.removeClass(self.options.addToCartButtonDisabledClass);
 addToCartButton.find('span').html(addToCartButtonTextDefault); //replace text() funtion to html() function here
 addToCartButton.attr('title', addToCartButtonTextDefault);
}, 1000);

Hope this will help you!

answered Dec 29, 2019 at 11:59
2
  • Thanks a lot! Did not saw that logic, quite easy :) Commented Dec 29, 2019 at 15:08
  • you are welcome bro Commented Dec 29, 2019 at 16:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.