1

I wanted to override the content of addtocart.phtml which is located in

vendor/magento/module-catalog/view/frontend/templates/product/view/addtocart.phtml

Now I want to modify the content of this and add this to my custom module located in

app/code/CustomVendor/CustomModule/view/frontend/templates/product/view/addtocart.phtml

But my changes does not appear. Is my path wrong? What or where should I place the custom addtocart.phtml file?

2 Answers 2

1

You have to override in to your theme to below path:

/var/www/html/magentoroot/app/design/frontend/Vendor/customtheme/Magento_Catalog/templates/product/view/addtocart.phtml

if you make addtocart.phtml in your custom module like

app/code/CustomVendor/CustomModule/view/frontend/templates/product/view/addtocart.phtml

you need to change catalog_product_view.xml layout too

1

if you want to override core template in your custom module then you have to create that particular layout file and write a code of "setTemplate" as below:

catalog_product_view.xml

<?xml version="1.0" encoding="UTF-8"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="product.info.addtocart">
            <action method="setTemplate">
           <argument name="template" xsi:type="string">Package_Module::product/view/addtocart.phtml</argument>
       </action>
    </body>
</page>

Then you can create a file inside your module according to a path defined in

Package/Modeule/view/frontend/templates/product/view/addtocart.phtml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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