0

I want to add custom link in More Information tab. See attached screenshot:

I want to give a link instead of text

enter image description here

0
  • Create an Attribute in admin with text type say external_link

  • Add phtml at:

app/design/frontend/{Package}/{theme}/Magento_Catalog/layout/catalog_product_view.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="product.info.addtocart">
            <block class="Magento\Catalog\Block\Product\View" name="external.link" template="Magento_Catalog::externallink.phtml"/>
       </referenceBlock>
    </body>
</page>

Now create phtml and get attribute value:

app/design/frontend/{Package}/{theme}/Magento_Catalog/templates/externallink.phtml

<?php $product = $block->getProduct(); ?>
<?php if($link = $product->getExternalLink()){ ?>
    <div class="link">
        <a href="<?= $link; ?>"><?= $block->escapeHtml(__('Link text')) ?></a>
    </div>
<?php } ?>

Hope above will help!

| improve this answer | |
  • Hi pawan, link should be different for all products. – gill Jul 25 at 6:20
  • Yes, that's why we created an attribute so you can add different link to each product! – Pawan Jul 25 at 6:26
  • Can we display same Custom link in more information tab. – gill Jul 25 at 8:45
  • Yes, you need to set Attribute Yes for Visible on Catalog Pages on Storefront in Storefront Properties tab – Pawan Jul 25 at 11:14
  • Thank you so much. code is working but can we display button instead of URL in more information tab. – gill Jul 25 at 21:35
0

Then you need to do the following things.

  1. first create one product attribute where you mention this link of third party.

  2. Now create one custom extension and create custom phtml file and call the file on product page on specific by using reference block.

  3. Now in that phtml file, fetch that product attribute value and show to customer.

| improve this answer | |
  • Hi Dhiren, Can we give a link instead of text in More Information tab. – gill Jul 27 at 23:22

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.