0

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

2

You need to overwrite following template and remove addtocart content.

vendor/magento/module-catalog/view/frontend/templates/product/list.phtml

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>
            </button>
        </form>
    <?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; ?>
</div>

Or use css for hiding this block.

For addto block you can remove using xml.Ex:

app/code/SR/MagentoCommunity/view/frontend/layout/catalog_category_view.xml

<?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">
    <body>
        <referenceContainer name="content">
            <referenceBlock name="category.product.addto" remove="true"/>
        </referenceContainer>
    </body>
</page>
  • 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? – Paul 'Whippet' McGuane Apr 28 at 14:58
  • Yes, css or directly remove from phtml – Sohel Rana Apr 28 at 16:15
  • Went the CSS route for now. Doesn’t feel right though. I would have thought it would be cleaner – Paul 'Whippet' McGuane Apr 29 at 9:12
0

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.