cancel
Showing results for 
Search instead for 
Did you mean: 

add custom message to product page

add custom message to product page

I want to show a custom message on the product page, delivery days message. like "next day delivery". is it possible? (under add to cart)

3 REPLIES 3

Re: add custom message to product page

@naftalayevf014 

 

You can override product view file into your theme and add required text into this file.

or you can override this file and find your attribute where you would like to add your text just put if condition there to add your text.

THEME/Magento_Catalog/templates/product/view/attribute.phtml

 

Manish Mittal
https://www.manishmittal.com/

Re: add custom message to product page

@naftalayevf014 If you want to add custom message just below add to cart then you can override the below file and add the message.

 

Current-Theme/Magento_Catalog/templates/product/view/form.phtml

if you are using any custom attribute for showing the message then you can use the below code to fetch the data.

$_product->getData('attribute_code');

Thanks

Re: add custom message to product page

Hi,

 

you can add a new block using a layout. For example if you have module Vendor_Module in app/code:

 

Create a file app/code/Vendor/Module/view/frontend/layout/catalog_product_view.xml

 

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
      <referenceContainer name="product.info.form.content">
        <block name="name_of_your_block" template="Vendor_Module::custom_message.phtml" after="product.info.addtocart"/>
      </referenceContainer>
    </body>
</page>

Create a file app/code/Vendor/Module/view/frontend/templates/custom_message.phtml

 

<?php
/** @var \Magento\Framework\View\Element\Template $block */

// here you can inject your custom message.

I recommend using ViewModel to pass data to template for example from product attribute if needed. Feel free if you have any questions. 

 

Regards,

Marcin Kwiatkowski

https://marcin-kwiatkowski.com