Search This Blog

May 8, 2012

Hiding add to cart button and/or product price for Customers who are not logged in

It is somewhat like doing a private sales, giving add to cart option for those customers that logged in. There are several magento extensions might have this functionality. But, in this post, I’ll show you on how to hide add to cart button and/or product price on your site easily.

What basically do is hiding them by using customer session. Ok, so let’s do it.
First off, you need to locate files that showing prices and add to cart buttons. Here are the files that you might look to.

1. Hiding Prices
app/design/frontend/default/default/template/catalog/product/price.phtml


2. Hiding Cart
app/design/frontend/default/default/template/catalog/product/list.phtml
app/design/frontend/default/default/template/catalog/product/view.phtml


After tracing those files that need to be edited, implement this code below.

<?php if (Mage::getSingleton('customer/session')->isLoggedIn()) : ?>

//INSERT THE CODE THAT YOU DIDN’T WANT TO APPEAR UNLESS CUSTOMER LOGGED IN

<?php endif; ?>

Here’s a complete example. If you want to hide the add to cart button on product view section, simply edit the view.phtml file from this directory (app/design/frontend/default/default/template/catalog/product/view.phtml)
Find the following code snippet on the view.phtml file:

<div class="add-to-holder">
<?php if($_product->isSaleable()): ?>
<?php echo $this->getChildHtml('addtocart') ?>
<?php if( $this->helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
<span class="add-or"><?php // echo $this->__('OR') ?></span>
<?php endif; ?>
<?php endif; ?>
<?php echo $this->getChildHtml('addto') ?>
</div>

Then, add this code in the beginning of the snippet code.
<?php if (Mage::getSingleton('customer/session')->isLoggedIn()) : ?>

Next, close the condition by adding this code at the end.
<?php endif; ?>

Ok, that’s the whole idea on how to do it. If you’re using a tier price or special price just use the same concept to hide the price.

0 comments: