1

How can i hide the price of products for a particular customer group? I want to hide the price everywhere for this customer including checkout,cart pages.

Magento_Newbie
  • 356
  • 2
  • 6
  • 22

1 Answers1

0

I had done it with plugin on same requirements,

Hide price box for specific customer group condition.

=> app/code/{{vendor}}/{{module}}/etc/di.xml

<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="{{vendor}}\{{module}}\Plugin\HidePriceBox" sortOrder="1" disabled="false"/>
    </type>
</config>

=>app/code/{{vendor}}/{{module}}/Plugin/HidePriceBox.php

<?php
namespace {{vendor}}\{{module}}\Plugin;
class HidePriceBox
{
    protected $_customerSession;
    protected $_customerGroupCollection;
public function __construct(        
    \Magento\Customer\Model\Session $customerSession,
    \Magento\Customer\Model\Group $customerGroupCollection
) {
    $this-&gt;_customerSession = $customerSession;    
    $this-&gt;_customerGroupCollection = $customerGroupCollection;
}

public function getCustomerGroup()
{       
    $currentGroupId = $this-&gt;_customerSession-&gt;getCustomer()-&gt;getGroupId();
    $collection = $this-&gt;_customerGroupCollection-&gt;load($currentGroupId); 
    $customer_group = $collection-&gt;getCustomerGroupCode();
    return $customer_group;
}

function afterToHtml(\Magento\Catalog\Pricing\Render\FinalPriceBox $subject, $result)
{
    $customerGroup = $this-&gt;getCustomerGroup();
    if($customerGroup == 'hide_customer_group')   //replace with customer group
    {
        return '';
    }
    return $result;
}

}

S.P
  • 1,534
  • 11
  • 16