Magento 2.2.5 – Change ‘Add To Cart’ to ‘View Product’ on Category Page

addtocartcategory-pagecategory-productsmagento-2.2.5

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!

Best Answer

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