how can i add a new price template to magento

how can i add a new price template to magento

August 29, 2026 · Illustrated author avatarBy Stefan Bogdanescu
how can i add a new price template to magento

Adding a New Price Template to Magento: A Step-by-Step Guide

Hello there! Today we’re going to tackle a common question I often see from Magento developers - how to add a new price template for the category view (list.phtml) without affecting the one used in the product detail page (view.phtml). Let’s dive right in!

Understanding the Default Price Template Structure

Before we proceed, it’s essential to understand that both list.phtml and view.phtml file use the same core template file located at template/catalog/product/price.phtml. This is why any changes made here will impact both pages.

The default price template structure in Magento follows this hierarchy:

app/design/frontend/package/theme/Magento_Catalog/templates/product/price.phtml

Creating a New Price Template File

To create a new price template that only applies to the category view, we need to introduce a new template file that will override the core one. Here’s how you can do it:

  1. Navigate to your theme folder:
app/design/frontend/package/theme/
  1. Create a new directory structure if it doesn’t exist:
catalog/product
  1. Inside this product directory, create a new file named price_list.phtml.

  2. Add the following content to this new file:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

use Magento\Framework\Pricing\Helper\Data;
use Magento\Framework\Pricing\PriceCurrencyInterface;

// Get current product
$product = $block->getProduct();
$_helper = $this->helper('Magento\Catalog\Helper\Output');

// Get store currency code
$currency = $block->getCurrentCurrencyCode();

// Get special price helper
$specialPriceHelper = $block->getSpecialPriceHelper();

if (!$_product->isGrouped()) {
    if ($_helper->canApplyMsrp($_product) == 1) {
        $_price = $this->catalogHelper->getProductPrice($_product, $_product->group_price, null, null);
        $_idPrefix = 'msrp';
    } else {
        $_price = $this->catalogHelper->getProductPrice($_product, null, null, null);
        $_idPrefix = 'base_price';
    }
} else {
    $_products = $block->getGroupedProductCollection();
    foreach ($_products as $_item) {
        if ($_helper->canApplyMsrp($_item) == 1) {
            $_price = $_item->getMsrpPrice();
            $_idPrefix = 'msrp';
        } else {
            $_price = $_item->getFinalPrice();
            $_idPrefix = 'base_price';
        }
    }
}

if ($_helper->canApplyMsrp($_product) == 1 || $_helper->canApplySpecialPrice($_product, 'final_price', 0)) {
    $price = $block->formatCurrency($_price);
} else if (isset($_item['regular_price'])) {
    $price = $block->formatCurrency($_item['regular_price']);
}

echo '<span class="special-price">';
echo $block->getSpecialPriceHtml($_product, $_item);
echo '</span>';

if (!$_helper->canApplyMsrp($_product) && !$_helper->canApplySpecialPrice($_product, 'final_price', 0)) {
    echo '<span class="regular-price">'
        . $block->formatCurrency($_price)
        . '</span>';
}
  1. Save the file.

Overriding the Core Template in list.phtml

Now that we have our new price template file (price_list.phtml), we need to tell Magento to use it specifically for the category view.

  1. Open your theme’s template/catalog/product/list.phtml file:
app/design/frontend/package/theme/Magento_Catalog/templates/product/list.phtml
  1. Find the line that includes the default price template (around line 34):
<?= $block->getProductPriceHtml($_item, 'list') ?>
  1. Replace it with this new code:
<?= $block->setTemplate('Magento_Catalog::product/price_list.phtml')->toHtml() ?>
  1. Save the file.

Clearing Cache and Verifying Changes

After making these changes, Magento won’t automatically recognize them until you clear its configuration cache:

  1. Navigate to your Magento admin panel.
  2. Go to System > Cache Management.
  3. Click “Flush Magento Cache”.
  4. Verify that the new price template is now applied on the category view page.

Wrapping Up

And there you have it! By following these steps, we’ve successfully created a new price template file for your list.phtml without touching the core or the view.phtml. This ensures that the special price isn’t displayed in the category view while maintaining its presence on the product detail page.

Remember, for more advanced customizations and themes, consider using Magento’s layout XML files. You can find an excellent guide to this on Laravel Company’s blog.

Happy coding!

Catalog Themes Pricing

Our network