Magento 2 – How to Hide Price from Front End with Custom Module

checkoutmagento2moduleordersprice

I have created one module and it has system configuration on the admin side, where the admin has the functionality to enable/disable the module. As per system configuration, I need to hide the price from every place on the front end.

i.e. "catalog, category, wishlist, a related product, upsell products,
cart, checkout, orders, email, account dashboard, etc.."

from everywhere I need to hide the price if the module is enabled.

Is there any global file for the price which can be overridden and add the code for hiding price?

I found one file, But if we override \Magento\Catalog\Pricing\Render\FinalPriceBox and change in wrapResult() function, it works but it will affect only product page and home page not for wishlist and other places.

how can I achieve this functionality? Is anyone have any idea about it?

Please share an idea to hide price from cart/checkout/order/etc…

Best Answer

Try below code:

app/code/Vendor/Module/etc/di.xml

<preference for="Magento\Catalog\Pricing\Render\FinalPriceBox" type="Vendor\Module\Pricing\Render\FinalPriceBox" />

app/code/Vendor/Module/Pricing/Render/FinalPriceBox.php

<?php

namespace Vendor\Module\Pricing\Render;

use Magento\Catalog\Pricing\Price;
use Magento\Framework\Pricing\Render;
use Magento\Framework\Pricing\Render\PriceBox as BasePriceBox;
use Magento\Msrp\Pricing\Price\MsrpPrice;


class FinalPriceBox extends \Magento\Catalog\Pricing\Render\FinalPriceBox
{ 
    protected function wrapResult($html)
    {
        return '';
    }

}
Related Topic