1

On magento 2.2.5 product detail page when I set a catalog price or or a special price what happens is the special price is shown first and then under it is the original price listed. i want to change this so that the original price is always listed first (above) any special price.

In my app/design/frontend/luma/Magento_Catalog/templates/product/view I see a price_cloned.phtml which idk what that does I tried editing the final_price.phtml (since this is for simple products) but that didn't do anything

1

Copy the following file:

magento_root/vendor/magento/module-catalog/view/base/templates/product/price/final_price.phtml

to:

magento_root/app/design/frontend/Vendor/theme/Magento_Catalog/templates/product/price/final_price.phtml

And use the below code for final_price.phtml

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

// @codingStandardsIgnoreFile

?>

<?php
/** @var \Magento\Catalog\Pricing\Render\FinalPriceBox $block */

$productId = $block->getSaleableItem()->getId();

/** ex: \Magento\Catalog\Pricing\Price\RegularPrice */
/** @var \Magento\Framework\Pricing\Price\PriceInterface $priceModel */
$priceModel = $block->getPriceType('regular_price');

/** ex: \Magento\Catalog\Pricing\Price\FinalPrice */
/** @var \Magento\Framework\Pricing\Price\PriceInterface $finalPriceModel */
$finalPriceModel = $block->getPriceType('final_price');
$idSuffix = $block->getIdSuffix() ? $block->getIdSuffix() : '';
$schema = ($block->getZone() == 'item_view') ? true : false;
?>
<?php if ($block->hasSpecialPrice()): ?>
    <span class="old-price">
        <?php /* @escapeNotVerified */ echo $block->renderAmount($priceModel->getAmount(), [
            'display_label'     => __('Regular Price'),
            'price_id'          => $block->getPriceId('old-price-' . $idSuffix),
            'price_type'        => 'oldPrice',
            'include_container' => true,
            'skip_adjustments'  => true
        ]); ?>
    </span>
    <span class="special-price">
        <?php /* @escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
            'display_label'     => __('Special Price'),
            'price_id'          => $block->getPriceId('product-price-' . $idSuffix),
            'price_type'        => 'finalPrice',
            'include_container' => true,
            'schema' => $schema
        ]); ?>
    </span>
<?php else: ?>
    <?php /* @escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
        'price_id'          => $block->getPriceId('product-price-' . $idSuffix),
        'price_type'        => 'finalPrice',
        'include_container' => true,
        'schema' => $schema
    ]); ?>
<?php endif; ?>

<?php if ($block->showMinimalPrice()): ?>
    <?php if ($block->getUseLinkForAsLowAs()):?>
        <a href="<?= /* @escapeNotVerified */ $block->getSaleableItem()->getProductUrl() ?>" class="minimal-price-link">
            <?= /* @escapeNotVerified */ $block->renderAmountMinimal() ?>
        </a>
    <?php else:?>
        <span class="minimal-price-link">
            <?= /* @escapeNotVerified */ $block->renderAmountMinimal() ?>
        </span>
    <?php endif?>
<?php endif; ?>
  • Thanks that doesnt work. So what I have is I am using the luma theme and customizing it. so I took the entire magento_root/vendor/magento/theme-frontend-luma folder and copied its contents to magento_root/app/design/frontend/luma . I then edit the file in the magento_root/app/design/frontend/luma/Magento_Catalog/templates/product/price/final_price.phtml . file but that doesn't work. it still seems to load it from the vendor folder. i also tried compiling and deploying even though I am in developer mode. No matter what I do it seems to load it from the vendor folder? – Jayreis Jun 28 at 14:09
  • you are doing wrong. What is your theme? It should be app/design/frontend/YOUR_VENDOR/YOUR_THEME/Magento_Catalog/templates/...... – Sukumar Gorai Jun 28 at 14:14
  • My theme is app/design/frontend/kiss/luma/ and then inside the luma folder I have a folder Magento_Catalog/templates/ – Jayreis Jun 28 at 14:35
  • Correct. It should work then – Sukumar Gorai Jun 28 at 14:38
0

You have to override this file:

\app\design\frontend\kiss\luma\Magento_Catalog\templates\product\price\final_price.phtml

Overridden code is here:

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

// @codingStandardsIgnoreFile

?>

<?php
/** @var \Magento\Catalog\Pricing\Render\FinalPriceBox $block */

/** ex: \Magento\Catalog\Pricing\Price\RegularPrice */
/** @var \Magento\Framework\Pricing\Price\PriceInterface $priceModel */
$priceModel = $block->getPriceType('regular_price');

/** ex: \Magento\Catalog\Pricing\Price\FinalPrice */
/** @var \Magento\Framework\Pricing\Price\PriceInterface $finalPriceModel */
$finalPriceModel = $block->getPriceType('final_price');
$idSuffix = $block->getIdSuffix() ? $block->getIdSuffix() : '';
$schema = ($block->getZone() == 'item_view') ? true : false;
?>
<?php if ($block->hasSpecialPrice()): ?>
    <span class="old-price">
        <?php /* @escapeNotVerified */ echo $block->renderAmount($priceModel->getAmount(), [
            'display_label'     => __('Regular Price'),
            'price_id'          => $block->getPriceId('old-price-' . $idSuffix),
            'price_type'        => 'oldPrice',
            'include_container' => true,
            'skip_adjustments'  => true
        ]); ?>
    </span>
    <span class="special-price">
        <?php /* @escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
            'display_label'     => __('Special Price'),
            'price_id'          => $block->getPriceId('product-price-' . $idSuffix),
            'price_type'        => 'finalPrice',
            'include_container' => true,
            'schema' => $schema
        ]); ?>
    </span>
<?php else: ?>
    <?php /* @escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
        'price_id'          => $block->getPriceId('product-price-' . $idSuffix),
        'price_type'        => 'finalPrice',
        'include_container' => true,
        'schema' => $schema
    ]); ?>
<?php endif; ?>

<?php if ($block->showMinimalPrice()): ?>
    <?php if ($block->getUseLinkForAsLowAs()):?>
        <a href="<?= /* @escapeNotVerified */ $block->getSaleableItem()->getProductUrl() ?>" class="minimal-price-link">
            <?= /* @escapeNotVerified */ $block->renderAmountMinimal() ?>
        </a>
    <?php else:?>
        <span class="minimal-price-link">
            <?= /* @escapeNotVerified */ $block->renderAmountMinimal() ?>
        </span>
    <?php endif?>
<?php endif; ?>

All this tested in my fresh setup, Also adding image here please check

enter image description here

Have updated file path as per your theme package please check.

  • when I move the file to my app/design/frontend/Magento_Catalog/view/base/templates/product/price/final_price.phtml clear cache but it doesnt seem to be referencing/using that file? – Jayreis Jun 28 at 13:20
  • Hi, I have updated my ans pls check. – Ravi Soni Jun 28 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.