How to remove the Add to Cart button from Catalog pages in Magento 2?
In Magento 2 they've hardcoded them into the catalog product list template.
This can be found around line 80 of app/code/Magento/Catalog/view/frontend/templates/product/list.phtml
:
<?php if ($_product->isSaleable()): ?>
<?php $postParams = $block->getAddToCartPostParams($_product); ?>
<form data-role="tocart-form" action="<?php /* @escapeNotVerified */ echo $postParams['action']; ?>" method="post">
<input type="hidden" name="product" value="<?php /* @escapeNotVerified */ echo $postParams['data']['product']; ?>">
<input type="hidden" name="<?php /* @escapeNotVerified */ echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php /* @escapeNotVerified */ echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
<?php echo $block->getBlockHtml('formkey')?>
<button type="submit"
title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
class="action tocart primary">
<span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
</button>
</form>
A few options exist to suppress them:
- Create an
around
plugin for the block and change$_product->isSaleable()
to return false for the render of the template, and swap it back afterward - Replace this template in your custom theme's layout
- Hide with CSS
Honestly hiding via CSS isn't the worst option here:
.catalog-category-view .action.tocart { display: none; }