2

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

2 Answers 2

1

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
0

First of all, you set the Manage stock to No it means Magento will not take care of stock qty item so it will not make any difference if your qty is 10000 or 0.(Because you are telling Magento that please don't take care of my stock) so Magento will display all the products by default.

Also, you are using 3rd party software for stock management so you need to make customization in such a way that it will check the qty/stock from the 3rd party and hide the add to cart button.

I am not sure which kind of 3rd party software you are using so I cannot write the code but Narendra wrote the file location in his answer so you can take some hint from there.

FYI, out of the box, Magento provides this feature(to hide out of the stock product) by just changing the configuration but it will work only if you set the Manage stock "yes"

enter image description here

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.