Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Hide prices and Add to Cart button in Magento

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 101
    Comment on it

    Hello Readers, Here is small example which will explain how to hide prices and ‘Add to Cart’ buttons for non-logged users in Magento.

    Hide prices in all pages:
    Go to Current theme (Path: app/design/frontend/currenttheme/default/template/catalog/product/price.phtml )
    Now, open price.phtml
    Copy the below code & paste it on top of price.phtml file:

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

    above code will hide the price details for unregistered users/non-logged in visitors.

    Hide the ‘Add to Cart’ button on product list page
    Go to /app/design/frontend/currenttheme/default/template/catalog/product/list.phtml & search for the following code.

    Replace 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; ?>

     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    }?>

    above code will hide the price details on List/category page for unregistered users/non-login users.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: