I need to redirect the specific product page when i click the add to cart button in the category page. instead of add the product to the shopping cart in magento 2.3.2

If anyone know the answer please share the exact code and folder structure since i'm new to magento.

enter image description here


you just need to override list.phtml file in your theme


and replace the code below:


<?php $postParams = $block->getAddToCartPostParams($_product); ?>
<form data-role="tocart-form"
      data-product-sku="<?= $block->escapeHtml($_product->getSku()) ?>"
      action="<?= $block->escapeUrl($postParams['action']) ?>"
    <input type="hidden"
           value="<?=  $postParams['data']['product'] ?>">
    <input type="hidden" name="<?=  Action::PARAM_NAME_URL_ENCODED ?>"
           value="<?=  $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">
    <?= $block->getBlockHtml('formkey') ?>
    <button type="submit"
            title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>"
            class="action tocart primary">
        <span><?= $block->escapeHtml(__('Add to Cart')) ?></span>


<button title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>"
        class="action primary">
    <a href="<?= $_product->getProductUrl() ?>"><span><?= $block->escapeHtml(__('Add to Cart')) ?></span></a>

Hope this will help you!

  • Hello Naresh, I have copied core list.phtml file code and replaced the code which you have shared. but still if i click the add to cart button, add the product to the shopping cart. instead of open the specific product. – Ramesh R Dec 11 '19 at 14:07
  • Code updated. please check with updated code and let me know it's working for you or not – Naresh Rupareliya Dec 12 '19 at 2:35
  • thank you naresh. it's working fine. – Ramesh R Dec 12 '19 at 7:35

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.