How to hide price in magento2

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 '';  

    }

}

Create module (eg: CatalogHidePrice) with plugin.
di.xml should look like:

<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="cataloghideprice_finalpricebox" type="NAMESPACE\CatalogHidePrice\Plugin\FinalPriceBox"/>
    </type>
</config>

In the plugin class \Plugin\FinalPriceBox\FinalPriceBox do an around plugin (for me, I have to hide the price based on a product attribute)

function aroundToHtml($subject, callable $proceed)
{

    if($subject->getSaleableItem()->getHidePrice()==1){
        return '';
    }else{
        return $proceed();
    }

}

Tags:

Magento2