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


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">
    <referenceContainer name="product.info.form.content">

        <block class="Vendor\Extension\Block\Catalog\Product\View\Enquiry" name="product.info.enquiry" after="product.info.addtocart"

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

  • Muhammad Hasham, of course, but after 5 minutes I’ll mark it, now it doesn't allow, "You can accept an answer in 5 minutes". ;) – Robinio Tor Mar 5 at 11:33

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.