I have tried to achieve this using answer from the question here Magento 2 : Add to cart button change to go to cart after adding product

However the button text is not changed immediately as the code is from phtml file and not js file.

I wish to achieve this using js(catalog-add-to-cart.js). To check if product is added to cart, I need to get cart items in this file. How do I get current user cart items here? Once the text is changed to Go to Cart, I also want to change the button link to cart url.


override catalog-add-to-cart.js


in your theme


line around 211 change

$t('Add to Cart'); to $t('Go to Cart');

setTimeout(function () {
                var addToCartButtonTextDefault = self.options.addToCartButtonTextDefault || $t('Add to Cart'); //change here

                addToCartButton.attr('title', addToCartButtonTextDefault);
            }, 1000);

after run command via ssh :

rm -rf pub/static/*;rm -rf var/view_preprocessed/*;rm -rf var/cache/*;rm -rf var/log/*;rm -rf var/di/*;rm -rf var/page_cache/*;rm -rf var/tmp/*;rm -rf var/generated/*;rm -rf generated/*;

php bin/magento setup:upgrade

php bin/magento setup:static-content:deploy -f

php bin/magento cache:clean

php bin/magento cache:flush

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.