We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

If you want to hide the whole website’s product price and want to make it appear only for login users then this article is a catch for you.

1. Create file di.xml on app/code/Magemonkeys/Hideproductprice/etc

<?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="MagentoCatalogPricingRenderFinalPriceBox">
        <plugin name="price_hide" type="MagemonkeysHideproductpricePluginHidePriceBox" sortOrder="1" disabled="false"/>
    </type>    
</config>

2. Create file HidePriceBox.php on app/code/Magemonkeys/Hideproductprice/Plugin

<?php

namespace MagemonkeysHideproductpricePlugin;

class HidePriceBox
{
    protected $_customerSession;
    public function __construct(        
        MagentoCustomerModelSession $customerSession    
    ) {
        $this->_customerSession = $customerSession;        
    }
	
    function afterToHtml(MagentoCatalogPricingRenderFinalPriceBox $subject, $result)
    {    
    	if($this->_customerSession->getCustomer()->getGroupId()) {
    		return $result;    		
    	}else{
        	return '<h3>PLEASE DO LOGIN AND SHOW THE PRICE</h3>';
        }        
    }
}

3. Result

field_5bfb909c5ccae

    Recent Articles
    Get a Free Quote