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?

asked May 28, 2019 at 15:02

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

answered May 29, 2019 at 5:42
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
answered May 29, 2019 at 5:56

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.