cancel
Showing results for 
Search instead for 
Did you mean: 

How can I remove add to cart button from home page?

How can I remove add to cart button from home page?

I just installed magento-2 now. I want to remove 'add to cart' button. How can I do this?

8 REPLIES 8

Re: How can I remove add to cart button from home page?

If you are asking about "Hot seller" call out area then you can remove add to cart button using following way:

Magento created one Widget name with "Home page" and this widget has called into static block "home-page-block".

This widget has called 

product/widget/content/grid.phtml

You can simple override your own created .phtml file with same without ""

Re: How can I remove add to cart button from home page?

Where is the

product/widget/content/grid.phtml

 ? I can't find it.

 

Home page means: the default index.php page with many product as grid view with "add to cart" button at bottom.

Re: How can I remove add to cart button from home page?

Hello @colam

 

it is inside \Magento\CatalogWidget\view\frontend\templates\product\widget\content

 

you need to check Magento\CatalogWidget module for same.

 

Hope it will help you.


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: How can I remove add to cart button from home page?

I removed these lines under /var/www/html/magento/vendor/magento/module-catalog-widget/view/frontend/templates/product/widget/content>grid.phtml, still there is 'add to cart' button

 

<div class="actions-primary">
                                                <?php if ($_item->isSaleable()): ?>
                                                    <?php if ($_item->getTypeInstance()->hasRequiredOptions($_item)): ?>
                                                        <button class="action tocart primary" data-mage-init='{"redirectUrl":{"url":"<?= $block->escapeUrl($block->getAddToCartUrl($_item)) ?>"}}' type="button" title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>">
                                                            <span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
                                                        </button>
                                                    <?php else: ?>
                                                        <?php
                                                            $postDataHelper = $this->helper('Magento\Framework\Data\Helper\PostHelper');
                                                            $postData = $postDataHelper->getPostData($block->getAddToCartUrl($_item), ['product' => $_item->getEntityId()])
                                                        ?>
                                                        <button class="action tocart primary" data-post='<?= /* @noEscape */ $postData ?>' type="button" title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>">
                                                            <span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
                                                        </button>
                                                    <?php endif; ?>
                                                <?php else: ?>
                                                    <?php if ($_item->getIsSalable()): ?>
                                                        <div class="stock available"><span><?= $block->escapeHtml(__('In stock')) ?></span></div>
                                                    <?php else: ?>
                                                        <div class="stock unavailable"><span><?= $block->escapeHtml(__('Out of stock')) ?></span></div>
                                                    <?php endif; ?>
                                                <?php endif; ?>
                                            </div>

 

Re: How can I remove add to cart button from home page?

Hello @colam

 

 

please flush cache and check it.

 

If still not working then enable hint path and check which file calling.

 

but

you can not change into core files, either you need to take into your theme or into your module

 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: How can I remove add to cart button from home page?

Run command,
php bin/magento cache:flush
If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: How can I remove add to cart button from home page?

How can I enable hint path?

 

"either you need to take into your theme or into your module" how can I do it?

 

Re: How can I remove add to cart button from home page?

Hi @colam

 

Re : How can I enable hint path?

 

  • Logged in to your magento 2 admin panel
  • then click on menu stores - > configuration -> Advanced -> Developer Over there in the Debug section - > You will find a dropdown menu called "Enable template path hints for storefront" -> choose YES from dropdown then click on save configuration
  • Clear cache !! you will see template hints on the frontend side

Note : You will find developer menu only when you are in Default or Developer mode - if you are in production mode then this Developer menu is hidden - so you need to change your mode if its not showing Developer menu to you !!

 

RE : "either you need to take into your theme or into your module" how can I do it?

 

- Meaning editing directly core files its not a preferable way - so you either need to create a custom module or custom theme to override this addtocart.phtml file to hide the addtocart button.

 

Now below i am sharing two links which gives you idea that how to create a module and hide the add to cart button .

 

https://magenticians.com/magento-2-disable-add-to-cart-button/

 

https://magenticians.com/hide-add-to-cart-guest-users-magento-2/

 

 

Hope it helps you !!

if issue solved,Click Kudos & Accept as Solution