3

Is it possible to change the 'Add To Cart' button to 'View Product' at the category pages? I have for almost every product some attributes, so it's weird for my visitors to click on "Add To Cart" but than go the the product with an alert that they have to choose the size and color..

Hope somebody can help me out!

asked Aug 15, 2018 at 13:45
2
  • You have using configurable product? Commented Aug 15, 2018 at 15:28
  • @AmitBera Yes. Configurable and simple products! Commented Aug 16, 2018 at 10:49

2 Answers 2

6

First you have to do this changes at your theme level.

Goto

app/design/frontend/{ThemeVendorname}/{ThemeName}/Magento_Catalog/templates/product/

And open list.phtml and delete the code:

<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>

And put this code

<div class="stock available">
<a class="product-item-link" href="<?= /* @escapeNotVerified */ $_product->getProductUrl() ?>">
 <span><?= /* @escapeNotVerified */ __('View Product') ?></span>
</a>
</div>
answered Aug 15, 2018 at 15:38
2
  • You're brilliant! It worked for me :-) Thank you very much. Do you also maybe know the following issue: magento.stackexchange.com/questions/237178/… Commented Aug 16, 2018 at 10:50
  • How to do same thing for only custom option available products Commented Mar 1, 2019 at 7:43
1

In addition to the solution of Amit above, this is only for the category page. To change it on the homepage i did the following too:

Goto

app/design/frontend/{ThemeVendorname}/{Themename}/{ThemeVendorname}_ProductWidget/templates/product/widget/content/list.phtml

Somewere in line 173 you see this code:

<button data-mage-init='{"redirectUrl":{"url":"<?php /* @escapeNotVerified */ echo $block->getAddToCartUrl($_item) ?>"}}'
 type="button"
 title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
 class="action tocart btn btn-default btn-cart">
 <span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
 </button>

Change this code with

<a href="<?php /* @escapeNotVerified */ echo $_item->getProductUrl() ?>" title="<?php echo __('View Product') ?>" class="btn btn-default"><?php echo __('View Product') ?></a>

Go to line 184 and see this code

<button data-post='<?php /* @escapeNotVerified */ echo $postData; ?>'
 type="button"
 title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
 class="action tocart btn btn-default btn-cart">
 <span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
 </button>

And change also this code with

<a href="<?php /* @escapeNotVerified */ echo $_item->getProductUrl() ?>" title="<?php echo __('View Product') ?>" class="btn btn-default"><?php echo __('View Product') ?></a>

Maybe you have to style the generated URL with CSS. Hope it helped somebody else too!

answered Aug 16, 2018 at 22:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.