Magento – Remove Regular Price from Product Page of Magento 2

configurable-productmagento2

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?

Best Answer

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; ?>
Related Topic