3

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> 

1
  • why should I include two reference block(product.info.addtocart, product.info.addtocart.additional)? what is the exact meaning of this Commented Jan 23, 2019 at 7:36

6 Answers 6

7

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> 
2
  • I have to add by extension file not by theme file Commented Feb 2, 2018 at 13:23
  • I have also used this code in extension but not working. Commented Feb 2, 2018 at 13:23
2

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> 
2

You can use the below code or create a new file in

app/code/Vendor/CustomBlock/view/frontend/layout/catalog_product_view.xml

Then you can add below content

<?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.extrahint"> <block class="Vendor\CustomBlock\Block\Catalog\Product\Presell" name="product.block_name" template="Vendor_CustomBlock::catalog/product/presellInfo.phtml" before="product.info.social"/> </referenceBlock> </body> </page> 
1

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

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

I had same issue and i fixed it by changing block name

 <?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-additional" template="Package_Name_Module_Name::catalog/product/view/enquiry.phtml"> </block> </referenceBlock> </body> 

change the name of second block so that it donot match with simple products block name

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.