2

I am doing a custom module and now I want to hide the 'add to cart' button for certain products. I have followed the https://magenticians.com/magento-2-disable-add-to-cart-button/ documentation and i was able to hide it from the product's detail page but not from the home/category page. I need this button hidden from all the views.

I have added the addtocart.phtml file to app/code/Magenticians/Mymodule/view/frontend/templates/catalog/product/view path and also the corresponding layout file as the document link said. It is working in detail page of the product only. I want it on all pages.

Thanks in advance!

2 Answers 2

1

Add to Cart button is not a separate file for the product listing page. You need to add your Add to Cart phtml file customization to the list.phtml file.

Copy list.phtml file from below path to your theme and make the required changes you've done in the addtocart.phtml file.

\vendor\magento\module-catalog\view\frontend\templates\product\list.phtml

Hope it helps!!!

1

For overriding list.phtml

Create view/frontend/layout/catalog_category_view.xml and put this code.

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <referenceBlock name="category.products.list">
        <action method="setTemplate">
            <argument name="template" xsi:type="string">Magenticians_Mymodule::product/list.phtml</argument>
        </action>
    </referenceBlock>
</body>

after, copy \vendor\magento\module-catalog\view\frontend\templates\product\list.phtml and paste it to
view/frontend/templates/product/list.phtml then make yur modifications

Your Answer

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

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