2

I want to disable add to cart and qty option if product is out of stock, but i also want to show price and swatches of the products and the swatches should be clickable and price should be changeable according to swatches I also want to show "add to cart and qnty option" but they should not be clickableenter image description here

in this case when product is out of stock, all options are not visible, swatches and price is not accessible , i want that price and swatches should be accessible and visible but quantity and add to cart option should be disable. Any idea how to do this? Thanks in advance.

2
  • check this link magento.stackexchange.com/questions/304604/…
    – Devidas
    Jul 26, 2022 at 7:10
  • it doest give the required output, button is not visibale when applied this solution, i want to show button but the action should not be performed when on click if product is out of stock Jul 26, 2022 at 7:36

1 Answer 1

0

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

for reference: https://magento.stackexchange.com/a/272688/92166

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.