Question

I want to add a new button to the product page , in which file can I add or should I create a module for this?

enter image description here

Was it helpful?

Solution

Using Block, we can display various information related to the product such as: Button, chart, discount, offers & deals, terms and conditions or caution etc.

Firstly, you need to create your custom module and after that you to create block using following code into your catalog_product_view.xml file. app\code\Vendor\Extension\view\frontend\layout\catalog_product_view.xml

    <?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<body>
    <referenceContainer name="product.info.form.content">

        <block class="Vendor\Extension\Block\Catalog\Product\View\Enquiry" name="product.info.enquiry" after="product.info.addtocart"
template="Vendo_Extension::catalog/product/view/file.phtml">
        </block>
    </referenceContainer>
</body>
</page>

Now, you need to create another file and named it as ‘File.phtml’, in which you have to add your custom code which you want to display in your custom block. app\code\Vendor\Extension\view\frontend\templates\catalog\product\view\file.phtml

Lastly, you need to create one block ‘Enquiry.php’ file here. In Which you can add your own logical functions. Vendor\Extension\Block\Catalog\Product\View\Enquiry.php

I hope this will help

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top