I am trying to remove the add to cart and add to compare buttons from the category page. At present I have used the following code:

<referenceBlock name="product.info.addtocart" remove="true" />
<referenceBlock name="product.info.options.wrapper.bottom" display="false" />

In my Magento_Catalog/layout/catalog_category_view.xml without any success


You need to overwrite following template and remove addtocart content.


Because addtocart content is hard coded. Like:

<div class="actions-primary"<?= strpos($pos, $viewMode . '-primary') ? $position : '' ?>>
    <?php if ($_product->isSaleable()): ?>
        <?php $postParams = $block->getAddToCartPostParams($_product); ?>
        <form data-role="tocart-form" data-product-sku="<?= $block->escapeHtml($_product->getSku()) ?>" action="<?= /* @NoEscape */ $postParams['action'] ?>" method="post">
            <input type="hidden" name="product" value="<?= /* @escapeNotVerified */ $postParams['data']['product'] ?>">
            <input type="hidden" name="<?= /* @escapeNotVerified */ Action::PARAM_NAME_URL_ENCODED ?>" value="<?= /* @escapeNotVerified */ $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">
            <?= $block->getBlockHtml('formkey') ?>
            <button type="submit"
                    title="<?= $block->escapeHtml(__('Add to Cart')) ?>"
                    class="action tocart primary">
                <span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
    <?php else: ?>
        <?php if ($_product->isAvailable()): ?>
            <div class="stock available"><span><?= /* @escapeNotVerified */ __('In stock') ?></span></div>
        <?php else: ?>
            <div class="stock unavailable"><span><?= /* @escapeNotVerified */ __('Out of stock') ?></span></div>
        <?php endif; ?>
    <?php endif; ?>

Or use css for hiding this block.

For addto block you can remove using xml.Ex:


<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceContainer name="content">
            <referenceBlock name="category.product.addto" remove="true"/>
  • the XML removed the compared/wishlist side of it, but not the button. Are you saying for the button the only way to remove it is to use CSS? – Boss Nass Apr 28 '19 at 14:58
  • Yes, css or directly remove from phtml – Sohel Rana Apr 28 '19 at 16:15
  • 1
    Went the CSS route for now. Doesn’t feel right though. I would have thought it would be cleaner – Boss Nass Apr 29 '19 at 9:12

add to cart is more of a block so when you want to remove a block you must edit files related to that block like layout.xml file, .phtml file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.