4

I don't want to use any commercial module for hiding price.and i don't want hide by using templates. is there any way to hide price from entire site using plug-ins or rewrites?

9

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

    }

}
  • its not working. changes not effect. – Yogesh Jul 6 '17 at 10:23
  • FinalBox isn't cached ? – siddhesh Jul 14 '17 at 15:20
  • Works great. I need to hide regular/final price on related section and how to achieve that? – Jai Aug 18 '17 at 11:24
  • well, i just figure out that this only worked for homepage and product detail page, but not with WISH LIST page. I still have change phtml file – fudu Oct 4 '18 at 2:43
4

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();
    }

}
  • I can't get the value of my attribute. These methods don't work: getMyAttribute() and getData('my_attribute'). Although the following method works $_product = $subject->getSaleableItem(); $myAttribute = $_product->getResource()->getAttribute('my_attribute')->getFrontend()->getValue($_product);. What could be the problem? – Victor S. Jul 5 '18 at 15:21
  • Lomosh HidePrice is an attribte? – NIPPU Nov 2 '18 at 6:56
1

The simplest way I can think of would be to just target the price's CSS class and hide it.

No modifying of any themes/template files required and can easily revert the changes by removing the style rule.

  • Have you got any example of this? – jibin george Jul 12 at 8:51
  • @jibingeorge it would vary depending on the theme/template, but just find the css class that is attached to the element you want hidden, then add or modify a style declaration to set it to display: none – codestr Aug 2 at 2: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.