1

I'm trying to remove the 'Regular Price' from the product page of a child luma theme I've created. My client only wants the special price showing.

Removing the regular price entries from the final_price.phtml and configured_price.phtml within my child theme doesn't make any difference.

/app/design/frontend/customtheme/child-luma/Magento_Catalog/templates/product/price/configured_price.phtml
/app/design/frontend/customtheme/child-luma/Magento_Catalog/templates/product/price/final_price.phtml

How do I remove the Regular Price?

  • Hello @Chris, did you try my solution ? – Pawan Mar 16 at 16:40
  • Hi @Pawan Yes, I already tried your solution (as detailed in my initial question). My problem is that copying the file to the child theme doesn't make any difference when amending it, it still shows the parent luma theme. – Chris Mar 18 at 15:23
1

Add following code to remove reguler price

app\code\MyVendor\MyModule\etc\di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="\Magento\Catalog\Pricing\Render\FinalPriceBox">
        <plugin name="MyVendor_MyModule_change_template" type="MyVendor\MyModule\Plugin\FinalPricePlugin" />
    </type>
</config>

app\code\MyVendor\MyModule\Plugin\FinalPricePlugin.php

<?php
namespace MyVendor\MyModule\Plugin;

class FinalPricePlugin
{
    public function beforeSetTemplate(\Magento\Catalog\Pricing\Render\FinalPriceBox $subject, $template)
    {
        if ($template == 'Magento_ConfigurableProduct::product/price/final_price.phtml') {
                return ['MyVendor_MyModule::product/price/final_price.phtml'];
         }
         else
         {
              return [$template];
         }

    }
}

\app\code\MyVendor\MyModule\view\frontend\templates\product\price\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 */

/** 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="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>
    <!--  Commant it to hide regular price  -->
   <!-- <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> -->

<?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; ?>
0

It is not necessary everything will be done from coding level. We can also make thing working using CSS/JS.

When any product having special price, there will be 2 different div with different class.

old-price and special-price.

If all of your product having special price, you can hide regular price by CSS.

Just Add:

.catalog-product-view .old-price {
    display: none;
}

Hope Above will help!

Update I

If you want to comment it you can copy base file form :

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

to

app/design/frontend/customtheme/child-luma/Magento_Catalog/templates/product/price/final_price.phtml

in above file there is a function if ($block->hasSpecialPrice()):, you can comment Regular price from here.

  • Thanks, but this is a last resort! I'd rather know how to make edits to the theme and they actually work. I never thought I'd miss Magento 1 – Chris Mar 7 at 0:19

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.