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?
-
1Free one: marketplace.magento.com/estdevs-hideprice.html– JacksonCommented Mar 23, 2017 at 9:00
-
this extension overriding template.there is a chance for template conflicts with custom themes.– Siva Kumar KoduruCommented Mar 23, 2017 at 9:20
-
You can look for anyone depending on your requirements magecomp.com/magento-2-hide-price.html magecomp.com/magento-2-call-for-price.html– Gaurav JainCommented Apr 14, 2017 at 5:56
-
I think this extension may solve your problems: mageplaza.com/magento-2-hide-price– James LeeCommented Dec 12, 2019 at 7:45
-
Please try our free plugin Magento 2 Hide Price Free. It hides prices for unauthorised Magento customers or replaces it with custom text or button with the popup message. You can configure it on store view level. Let us know how it worked for you! mageme.com/magento-2-hide-price-extension-free.html– MageMeCommented Feb 8, 2020 at 2:50
4 Answers
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 '';
}
}
-
-
1
-
Works great. I need to hide regular/final price on related section and how to achieve that? Commented Aug 18, 2017 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– fuduCommented Oct 4, 2018 at 2:43
-
Can you please tell me how to get a product id within this plugin Commented Feb 13, 2020 at 5:46
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()
andgetData('my_attribute')
. Although the following method works$_product = $subject->getSaleableItem(); $myAttribute = $_product->getResource()->getAttribute('my_attribute')->getFrontend()->getValue($_product);
. What could be the problem? Commented Jul 5, 2018 at 15:21 -
Try This code
app/code/Vendorename/ModuleName/etc/frontend
di.xml
<?xml version="1.0" encoding="UTF-8"?>
<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="price_hide" type="Vendorename\ModuleName\Plugin\HidePriceBox" sortOrder="1" disabled="false"/>
</type>
</config>
app/code/Vendorename/ModuleName/Plugin
HidePriceBox.php
<?php
namespace Vendorename\ModuleName\Plugin;
class HidePriceBox
{
function afterToHtml(\Magento\Catalog\Pricing\Render\FinalPriceBox $subject, $result)
{
// add your logic
if (condition) {
return '';
} else {
return $result;
}
}
}
I Hope This Helps You.
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.
-
-
@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
– codestrCommented Aug 2, 2019 at 2:19