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 '18 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. – Andrew Luong Nov 7 '18 at 14:42
  • Hello @Andrew, Did you try my solution ? – Pawan Nov 20 '18 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 – Andrew Luong Nov 28 '18 at 16:35

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 '18 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 – Andrew Luong Nov 28 '18 at 16:27
  • Good 2 know that @AndrewLuong :) – Pawan Nov 28 '18 at 16:31
  • You can accept and up vote answer :) – Pawan Nov 28 '18 at 16:32
  • be my friend with me Pawan, my email is: dinhkinh2012@gmail.com so if you want to contact me, just type some text for it, I'm happy to hear you, friend :) – Andrew Luong Nov 28 '18 at 16:38

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.