Magento2 How can I display product Added to cart success message under Add to cart button on product details page?
2 Answers
Posting answer might be helpful for some one.
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<move element="page.messages" destination="product.info.form.content" after="product.info.addtocart" />
</body>
</page>
In catalog_product_view.xml
First of all, you need to override the vendor catalog_product_view.xml file in your theme. if it does not exist in your theme that i have given below or this file already exists in your theme so just add the given below code on the body tag.
vendor/magento/module-catalog/view/frontend/layout/catalog_product_view.xml
to
app/design/frontend/[Vendor]/[MyCustomTheme]/Magento_Catalog/layout/catalog_product_view.xml
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<move element="page.messages" destination="product.info.addtocart" />
</body>
</page>