Magento: How to add text before price

Magento: How to add text before price

July 27, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: How to add text before price

Magento: How to Add Text Before Product Price on Category Page

As an e-commerce developer working with Magento, you might find yourself needing to add custom text before the product prices displayed in your shop’s category pages. This is particularly useful when you want to provide additional information about your products’ pricing structure or promotional offers.

Understanding the Problem

Let’s say you have a configurable product and you want to display a message like “Tax included” or “Starting at $XYZ” before each price on a category page. The default Magento theme (like Modern) doesn’t provide this functionality out of the box.

The Solution: Using Layout XML Updates

To achieve this, we’ll use layout XML updates to override the existing blocks and insert our custom text. Here’s how you can do it:

  1. First, create an XML file in your custom extension or theme folder (let’s say app/design/frontend/Vendor/theme/Magento_Catalog/layout/default.xml). If the directory doesn’t exist, create it.

  2. Add the following code to this file:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="category.products.list">
            <block class="Magento\Framework\View\Element\Template" name="custom.price.message"
                   as="customPriceMessage" template="Magento_Catalog::product/price_message.phtml"/>
            <action method="insertBefore">
                <argument name="name" xsi:type="string">customPriceMessage</argument>
                <argument name="blockName" xsi:type="string">category.products.list</argument>
                <argument name="index" xsi:type="number">0</argument>
            </action>
        </referenceBlock>
    </body>
</page>
  1. Create the template file app/design/frontend/Vendor/theme/Magento_Catalog/templates/product/price_message.phtml and add your custom message:
<?php echo $this->getMessage(); ?>
  1. In your theme’s template/mobile/html/topmenu.phtml, find the line where the price is rendered (it might be around line 156). Add the following immediately before it:
echo $block->getChildHtml('customPriceMessage');

Making It Work with Your Custom Message

To make this work, you need to create a getter for your custom message. In your theme’s Magento_Catalog module, add a new file app/design/frontend/Vendor/theme/Magento_Catalog/etc/di.xml:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Catalog\Model\Product">
        <plugin name="add_price_message" type="Vendor\Theme\Model\Plugin\AddPriceMessage"/>
    </type>
</config>

Then, create the plugin file app/code/Vendor/Theme/Model/Plugin/AddPriceMessage.php:

<?php

namespace Vendor\Theme\Model\Plugin;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Store\Model\ScopeInterface;

class AddPriceMessage
{
    const PRICE_MESSAGE_CONFIG_PATH = 'catalog/price_message';

    protected $scopeConfig;

    public function __construct(
        ScopeConfigInterface $scopeConfig
    ) {
        $this->scopeConfig = $scopeConfig;
    }

    public function afterGetFinalPrice(\Magento\Catalog\Model\Product $subject, $result)
    {
        $message = $this->scopeConfig->getValue(self::PRICE_MESSAGE_CONFIG_PATH, ScopeInterface::SCOPE_STORE);
        return $result . ' <span style="font-size:12px;">' . $message . '</span>';
    }
}

Configuring the Message

Finally, you can configure the message in your backend under Stores > Configuration > Catalog > Price Display Options.

Conclusion

In this tutorial, we’ve demonstrated how to add custom text before product prices on Magento category pages using layout XML updates and a simple plugin. This approach is flexible and allows you to easily change the message across all products without modifying core files.

Remember to clear your cache after making these changes. For more information on working with Magento themes and customizations, check out our comprehensive guide at [Laravel Company](https://laravelcompany.com/magento-development Guide).

Happy coding!

Catalog Extensions Themes Configuration

Our network