0

I am trying to override

vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js 

to

app/design/frontend/MyTheme/Package/Magento_Catalog/web/js/catalog-add-to-cart.js

in order to change the "Add to Cart" button text. I modified the only instance of "Add to Cart" in the js file.

 setTimeout(function () {
            var addToCartButtonTextDefault = self.options.addToCartButtonTextDefault || $t('Add to Basket');

I fired cache:clean, cache:flush, setup:upgrade, but the text is still not changing. What step am I missing?

2

There are 2 places where you need to change the text and then it will show your changes these are ( if these files are not in your theme then place these files in your theme folder , where i assume **/Vendor/theme** is your theme folders ):

1 - /Vendor/theme/Magento_Catalog/templates/product/view/addtocart.phtml in this file you should change

<?php **$buttonTitle = __('Add to Basket');** ?>

this will change button title but only when it will load the page , but when you will hit that button it will change back to "Add to cart". So you need to make change in js file ( which you have mentioned in your question already )

2 - /Vendor/theme/Magento_Catalog/web/js/catalog-add-to-cart.js

var addToCartButtonTextDefault = self.options.addToCartButtonTextDefault || $t('Add to Basket');

If you are already in developer mode then :

After making these changes you just need to run cache:clean command if that still not work then deploy:static:content.

3

you just need to add your text into language csv file, no need to override any js file

app/design/frontend/Customtheme/default/i18n/en_US.csv

add like "Add to Cart","Add to Basket"

run below command

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

check your changes.

1

To change the text of "Add to Cart" button, you need to do changes in its view template file.

-- Enable template path hint from admin and find the path of template file of that button.

-- Override that template view file in your theme folder and then do required changes.

0

Your rrequirement is to change text of "Add To Cart" button then you need to do using custom extension by overiding this.

  1. You need to overide "addtocart.phtml" file.

    app\code\Vendor\Extension\view\frontend\layout\catalog_product_view.xml
    

    <body>
        <referenceBlock name="product.info.addtocart">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Vendor_Extension::catalog/product/view/addtocart.phtml</argument>
            </action>
        </referenceBlock>
    </body>
    

    1. create template file "addtocart.phtml" file at this location.

      app\code\Vendor\Extension\view\frontend\templates\catalog\product\view\addtocart.phtml
      

Into this file, copy orignal file code, just replace this line.

<?php $buttonTitle = __('Add to Cart'); ?>

to

<?php $buttonTitle = __('Add to Basket'); ?>

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.