0

I feel like i've read and tried every solution i possibly could and nothing works.

I removed from product page by overiding .phtml files in custom theme, easy.

I then successfully removed from the product grid but then after around an hour or two i noticed it was back and since i haven't been able to get rid of it.

I put the files back to how they were and then did the exact same steps again and nothing.

Im really at a los and cant understand why theres not just a button in the settings to disable this. I know there is something you can set in php somewhere to disable it but i have no idea where or how to do that.

I also understand this can be done in xml but again i have no idea how or what xml file to change. i installed a module and a chrome extension to get the xml block names but i cant get any of my attempts to change any thing.

Any help would be greatly appreciated.

0

Create an after plugin for the product model isSalable method:

in Your/Module/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="\Magento\Catalog\Model\Product">
        <plugin name="your_module_addtocart" type="Your\Module\Plugin\Magento\Catalog\Model\Product"
                sortOrder="10"/>
    </type>
</config>

in Your\Module\Plugin\Magento\Catalog\Model\Product.php

<?php

namespace Your\Module\Plugin\Magento\Catalog\Model;


/**
 * Plugin to turn off add to cart buttons
 *
 */
class Product
{
    /**
     * Override Product->isSaleable() to disable add to cart
     *
     * @param \Magento\Catalog\Model\Product $product
     * @param bool $result
     * @return bool
     */
    public function afterIsSalable(
        \Magento\Catalog\Model\Product $subject,
        $result
    ) {
       return false;
    }
}

This will make all products not salable and remove the "Add to Cart Button". It will take care of the catalog categories, product view and anywhere else the product is rendered on the site.

0

In Magento 2 it is hardcoded in 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>

You can hide via CSS below. Othwerwise override that template in your custom theme and remove that add to cart html code.

.catalog-category-view .action.tocart { display: none; }

To remove from product detail, see answer Magento 2: How to remove add to cart template from product detail page

  • I have tried that but i will try again and get back to you. thanks for the answer – Carl Piper Jul 20 '18 at 15:22
  • I just tried it and it does nothing, i dont understand why. this is how i always did it in Magento 1.9 and how i still do it in Magento 2 in most places. there has to be something overriding this file that i just cant seem to find. like i said in my original question it was working, it had disappeared but then it returned. – Carl Piper Jul 20 '18 at 15:28

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.