Skip to content

Remove or replace add to cart button on a product in catalog by condition programmatically

Preconditions:

  • Magento 2 clean installation with Luma.
  • We shouldn’t use templates.
  • The replacement needs to create a popup form related to product data to send and save it to my grid.

I’m searching for a way to replace the add to cart button from a product in the Magento catalog with my condition. I found the only way to hide the button with JS and set my button instead, but it’s not a “clean” way and I know that we can do it more correctly, probably with an observer or plugin.