{"id":425,"date":"2019-05-20T10:50:04","date_gmt":"2019-05-20T10:50:04","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2019\/05\/20\/add-block-before-add-to-cart-button-in-magento-2-product-page\/"},"modified":"2025-05-22T16:51:17","modified_gmt":"2025-05-22T11:21:17","slug":"add-block-before-add-to-cart-button-in-magento-2-product-page","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/add-block-before-add-to-cart-button-in-magento-2-product-page\/","title":{"rendered":"How to Add Block Before Add to Cart Button in Magento 2 Product Page"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">From landing on a product page to completing the whole buying cycle, product page plays a vital role in conversion.&nbsp;Hence the product page must be designed in such a way that can provide enough information prior to making a purchase, impress the visitors, push them for conversion and be customer friendly for online purchases!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You may sometimes need to tweak the default Magento 2 product page a bit here and there. You may want to add a little notice that you want your customer to see before adding the product to cart or may want to convey essential details before they proceed to checkout!&nbsp;To serve the purpose, you need to <i><strong>add block before Add to Cart button in Magento 2 product page<\/strong><\/i>. Use the below code the right way and you are done!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Add Block Before Add to Cart Button in Magento 2 Product Page:<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Add the below code in your&nbsp;<strong>catalog_product_view.xml<\/strong>&nbsp;file at&nbsp;<em><strong><em><strong>Vendor\\Extension\\view\\frontend\\layout<\/strong><\/em><\/strong><\/em><\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\"?>\n&lt;page xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View\/Layout\/etc\/page_configuration.xsd\">\n    &lt;body>\n        &lt;referenceBlock name=\"product.info.form.content\">\n            &lt;block class=\"Vendor\\Extension\\Block\\Catalog\\Product\\View\" name=\"catalog.product.view.extrablock\"\n                   as=\"extra_options\" before=\"product.info.addtocart\" template=\"Vendor_Extension::catalog\/product\/view.phtml\"\/>\n        &lt;\/referenceBlock>\n    &lt;\/body>\n&lt;\/page><\/pre>\n\n\n\n<ul start=\"2\" class=\"wp-block-list\">\n<li>Create new<strong>&nbsp;view.phtml file<\/strong>&nbsp;at&nbsp;<em><strong><em><strong>Vendor\\Extension\\view\\frontend\\templates\\catalog\\product<\/strong><\/em><\/strong><\/em><\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;h2>\n    new block call\n&lt;\/h2><\/pre>\n\n\n\n<ul start=\"3\" class=\"wp-block-list\">\n<li>Create<strong>&nbsp;View.php file&nbsp;<\/strong>at&nbsp;<em><strong><em><strong>Vendor\\Extension\\Block\\Catalog\\Product<\/strong><\/em><\/strong><\/em><\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nnamespace Vendor\\Extension\\Block\\Catalog\\Product;\nuse Magento\\Catalog\\Block\\Product\\Context;\nuse Magento\\Catalog\\Block\\Product\\AbstractProduct;\n\nclass View extends AbstractProduct\n{\n    public function __construct(Context $context, array $data)\n    {\n        parent::__construct($context, $data);\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That was all!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Another amazing thing you can do while customizing the product page is to use <a title=\"How to Use Custom Price Template in Magento 2\" href=\"https:\/\/meetanshi.com\/blog\/how-to-use-a-custom-price-template-in-magento-2\/\">custom price template in Magento 2<\/a> to change the way prices are displayed to the customers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ain&#8217;t the tutorial an easy-to-follow type?&nbsp; <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>From landing on a product page to completing the whole buying cycle, product page plays a vital role in conversion.&nbsp;Hence the product page must be&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-425","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/425","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=425"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/425\/revisions"}],"predecessor-version":[{"id":15422,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/425\/revisions\/15422"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=425"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}