Do you know how to Change text and Relink the "Add To Cart" button in the product list page (need to change code in the file list.phtml).

In my magento server, the list.phtml file is located in the theme directory. I'm using magento 2.2.6: /public_html/app/design/frontend/Hiddentechies/pixtron/Magento_Catalog/templates/product/list.phtml

I can change the button text from "Add To Cart" to "Find Out More", but can not relink it.

To relink the button, I created an atrribute 'get_link' for each product to store the external URL from admin's input, when customer click "Find Out More" button, it will direct user to the external URL's page in the web browser.

<button type="button"
    title="<?php echo $block->escapeHtml(__('Find Our More')); ?>"
    class="action tocart primary"
    onclick='window.location.href="<?php echo $_product->getData('get_link'); ?>"'>
    <span><?php /* @escapeNotVerified */ echo __('Find Our More') ?></span>

It's difficult because I don't know how to take the value in the 'get_link' atrribute in file list.phtml, it's not the same way to take the 'get_link' atrribute in file addtocart.phtml:


and there is also a FOR loop to print all products in the same category, so that I don't know how to get the value of 'get_link' for each product:

<?php foreach ($_productCollection as $_product): ?>

I know it's not easy but hope you will take a time to help. Or just give me somewhere I can find solution for this.

Thank you a lot.

  • when you clicking this button, what you are getting ?
    – Pawan
    Nov 4, 2018 at 13:27
  • Thank you @Pawan :) it reload the page but nothing happen, I try to print the value of get_link but it doesn't print anything, this means it can not get the value of "get_link", the value of get_link is visible to the product page, but not visible to the list page. Nov 7, 2018 at 14:42
  • Hello @Andrew, Did you try my solution ?
    – Pawan
    Nov 20, 2018 at 3:56
  • Hello @Pawan, I have tried this, the button can not get the url value of 'get_link' because I set "get_link" is not visible with the product list page, after I enable it for the product list page in Magento admin setting, the button can read the value of "get_link" and it works. thank you Pawan, hope the best for you my friend Nov 28, 2018 at 16:35

1 Answer 1


Change your button code at



<button type="button"
    title="<?php echo $block->escapeHtml(__('Find Our More')); ?>"
    class="action tocart primary"
    onclick='window.location.href="<?php echo $_product->getGetLink(); ?>"'>
    <span><?php /* @escapeNotVerified */ echo __('Find Our More') ?></span>

Above button is creating in a loop, So it will take value for each product.

  • Did you try my solution ? Or need further help ?
    – Pawan
    Nov 26, 2018 at 16:29
  • Hello @Pawan, thank you a lot, I have tried your solution and it works well, I'm sorry for replying late, my friend, hope you have nice day, ^^ it's very happy to have the support from you Pawan, ^^ Do you like music Pawan, could I give you a song for relax :) youtube.com/watch?v=iQ3dD6ASTgM Nov 28, 2018 at 16:27
  • Good 2 know that @AndrewLuong :)
    – Pawan
    Nov 28, 2018 at 16:31
  • You can accept and up vote answer :)
    – Pawan
    Nov 28, 2018 at 16:32
  • be my friend with me Pawan, my email is: [email protected] so if you want to contact me, just type some text for it, I'm happy to hear you, friend :) Nov 28, 2018 at 16:38

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.