Breadcrumbs

Home Web Development Hide price in Magento, hide price for visitors in Magento 1.x
Hide price in Magento, hide price for visitors in Magento 1.x PDF Print E-mail
Written by Tom   

The below instructions will let you hide price for guest visitors to your Magento store. The instruction will only work for Magento 1.x. From Magento 1.7 to 1.9. The instructions are done in php code.

 

1. Let’s hide prices for all guest visitor everywhere in your Magento store.

 

  • Open app/design/frontend/base/default/template/catalog/product/ folder and copy price.phtml file to the
  • app/design/frontend/base/template/themeXXX/catalog/product/ folder, where XXX is the name of your theme, and then place the following code on top of it:



<?php
if(!Mage::getSingleton('customer/session')->isLoggedIn()){
echo '<span class="login_for_price"><strong>Login to See Price</strong></span><br>';
return;
}
?>



2. Now we will hide the ‘Add to Cart’ button on category list page. (This step may be optional as some themes do not use this code).
  • Open /app/design/frontend/default/themeXXX/template/catalog/product/list.phtml file and look for the following code:


<?php if($_product->isSaleable()): ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button><br>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif;
?>
  • and replace it with:
<?php
if(!Mage::getSingleton('customer/session')->isLoggedIn()){
echo '<span class="login_for_details" style="float:left"><strong>Login to Add to Cart</strong></span>';
}
else{
?>
<?php if($_product->isSaleable()): ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button><br>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<?php    }
?>


3. Now we will hide the ‘Add to Cart’ button on product detail page.
  • Open app/design/frontend/default/themeXXX/template/catalog/product/view/addtocart.phtml file.
  • Add the following code on top of it:


<?php if($_product->isSaleable()): ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button><br>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif;
?>


4. In order to hide the ‘Add to Cart’ button for for new products. (This step may be optional as some themes do not use this code).
  • Open /app/design/frontend/default/themeXXX/template/catalog/product/new.phtml file and look for the following code:


<?php if($_product->isSaleable()): ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button><br>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif;
?>
  • and replace it with:
<?php
if(!Mage::getSingleton('customer/session')->isLoggedIn()){
echo '<span class="login_for_details" style="float:left"><strong>Login to Add to Cart</strong></span>';
}
else{
?>
<?php if($_product->isSaleable()): ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button><br>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<?php    }
?>


For more detailed info click here.