Magento – Magento 2 How to Disable Add to Cart Button for Out of Stock Products

addtocartmagento2out-of-stock

Magento 2.3

I have a 3rd part software I use for stock management so dont need Mangeto to manage my stock.
If I set the manage stock option to no then the add to cart button on the product page is still displayed even if the stock quantity is zero.

How can I disable the add to cart button or even hide the product when stock reaches zero.

I have set the display out of stock products option to no already but this didn't help.

Any advice greatly appreciated

Best Answer

All that if you want is not to show the "Add to cart" button. You will be in need to remove the block responsible for adding that on details page.

Have a look at this file:

vendor/magento/module-catalog/view/frontend/layout/catalog_product_view.xml

The block adding "Add to cart" is:

name="product.info.addtocart"

** Do not make change in vendor you need to override the same in your theme and remove that block.

If you do not want to remove it you can have a look at:

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

Again do not change in vendor override this file and you can apply condition/change as per yours need.

But with this changes will only be applicable on product view page. In order to perform customization on list view, have a look at this file:

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

If stock reaches "0" and if from backend you have set not to display out of stock products then ideally it should not display. You can try by reindexing:

php bin/magento i:rei
Related Topic