How to Hide product price for not login user in magento?
In this post we will show you How to hide price for not login user in magento. In some case we need to hide product price for not login user or guest usercustome login. At that time this following code will hel you to Hide product price in magento.
Note : You nedd add this code in your “AddyourModule” and replace “AddyourModule” in following code.
1) Go to /app/etc/config.xml
And Open your config.xml
file and add following code under global tag.
... ... ...... Company_AddyourModule_Helper_Product Company_AddyourModule_Helper_Checkout
2) Now add following script in your “AddyourModule” helper file.
Go to /app/code/local/Company/AddyourModule/Helper/Product.php
For Helper files. If file is not exist then go to /app/code/core/Company/AddyourModule/Helper/Product.php
and copy and paste /app/code/local/Company/AddyourModule/Helper/Product.php
File.
class Company_AddyourModule_Helper_Product extends Mage_Catalog_Helper_Product { /** * From anonymous users Overridden to Hide product price. * hide price for not login user * @param Mage_Catalog_Model_Product $product = product data * @param bool $displayMinimalPrice = bool Price data * @return string = string result return */ public function getPriceHtml($product, $displayMinimalPrice = false) { $is_loggedin = Mage::getResourceSingleton('customer/session')->isLoggedIn(); // user is login if (! $is_loggedin ) { // return message not allow and Hide product price for not login user return "You must be logged into to see the price."; } // return message as prise return parent::getPriceHtml($product, $displayMinimalPrice); } }
3) Now add following script in your “AddyourModule” helper file.
Go to /app/code/local/Company/AddyourModule/Helper/Checkout.php
For Helper files. If file is not exist then go to /app/code/core/Company/AddyourModule/Helper/Checkout.php
and copy and paste /app/code/local/Company/AddyourModule/Helper/Checkout.php
File.
class Company_AddyourModule_Helper_Checkout extends Mage_Checkout_Helper_Data { /** * * From anonymous users we Overridden to hide price. * Hide product price for not login user */ public function formatPrice($price) { $is_loggedin = Mage::getResourceSingleton('customer/session')->isLoggedIn(); // user is login if (! $is_loggedin ) { // return message not allow and hide product price for not login user return "N/A"; //return "You must be logged into to see the price."; } // return message as prise return parent::formatPrice($price); } }