0

I have to add block and call custom phtml file after "Add to Cart" button on product details page.

I have added below code in catalog_product_view.xml file in extension.

It is working but displaying before Qty input box

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <referenceContainer name="alert.urls">
        <block class="Package_Name\Module_Name\Block\Catalog\Product\View\Enquiry" name="product.info.enquiry" template="Package_Name_Module_Name::catalog/product/view/enquiry.phtml" after="-" />
    </referenceContainer>
</body>

But it's not working

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <referenceBlock name="product.info.addtocart">
        <block class="Package_Name\Module_Name\Block\Catalog\Product\View\Enquiry"name="product.info.enquiry" template="Package_Name_Module_Name::catalog/product/view/enquiry.phtml">
        </block>
    </referenceBlock>
    <!-- for config products -->
    <referenceBlock name="product.info.addtocart.additional">
        <block class="Package_Name\Module_Name\Block\Catalog\Product\View\Enquiry" name="product.info.enquiry" template="Package_Name_Module_Name::catalog/product/view/enquiry.phtml">
        </block>
    </referenceBlock>
</body>

  • why should I include two reference block(product.info.addtocart, product.info.addtocart.additional)? what is the exact meaning of this – senthil Jan 23 '19 at 7:36
2

Use below step to add block/template below the Add to Cart button

Create file in your module/theme catalog_product_view.xml

and add below code

<?xml version="1.0"?>
<page
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="product.info.options.wrapper.bottom">
            <block
                class="[Compney]\[Module]\Block\Catalog\Product\Block"
                name="product.info.anyname"
                template="[Compney]_[Module]::catalog/product/phtmlfile.phtml"
                after="product.info.addtocart"/>
        </referenceBlock>
    </body>
</page>
  • I have to add by extension file not by theme file – Magecode Feb 2 '18 at 13:23
  • I have also used this code in extension but not working. – Magecode Feb 2 '18 at 13:23
0

Refer this question.I am also needed this kind of solution,It was helped to me.

Add new container in Group product View Page in Magento 2

It will definitely help you.

This answer is for grouped product.If you want to simple product page,remove the if condition if($block->getProduct()->getData('type_id')=='grouped'): from the answer.

0

You need to try this code.

<?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="Package_Name\Module_Name\Block\Catalog\Product\View\Enquiry" name="product.info.enquiry" after="product.info.addtocart" template="Package_Name_Module_Name::catalog/product/view/enquiry.phtml">
        </block>
        </referenceContainer>
   </body>
</page>
0

you are using same block name in both the blocks that is why its not working.

Try below code

<referenceContainer name="product.info.form.content">
        <block class="Namespace\Module\Block\XYZ" name="block.name.one" as="makeoffer.button" template="Namespace_Module::template.phtml" after="product.info.addtocart"/>
</referenceContainer>
<!-- for config products -->
<referenceBlock name="product.info.options.wrapper.bottom">
        <block class="Namespace\Module\Block\XYZ" name="block.name.two" as="makeoffer.button.additional" template="Namespace_Module::template.phtml" after="product.info.addtocart"/>
</referenceBlock>

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.