I want to hide price from non registered users in magento 2 for specific products. I want to do this functionality by using any observer or plugins not from direct conditions in overwritten phtml files.
1 Answer
First check if user is logged in or not
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
if($customerSession->isLoggedIn()) {
// show price
}else {
// show some custom message or hide complete price logic
}
Must read : How to check if customer is logged in or not in magento 2?