0

I want a to add a link the customer can click which will redirect them to another page(a product) on the site. How can i achieve this? Ideally I'd like the link to be in the section where customer chooses product option(See image)

Product Options

1 Answer 1

0

You can create link.phtml file in the Magento_Catalog module.

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

`

Call this file in 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="link" template="Magento_Catalog::link.phtml"/>
   </referenceBlock>
</body>

Hope it will work.

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.