3

How can I Disable the "add to cart" when user is not logged in.

4

2 Answers 2

0

Please check with below module, which is provide to not login user hide product price.

https://github.com/Tartilas/Magento-hideprice

Also if you want to do via pragmatically than check with below event. Using below event to set price equals to zero

first event :

<catalog_product_get_final_price>
           <observers>
             <hideprice_catalog_price_observer>
               <type>singleton</type>
               <class>Wsc_Postcode_Model_Observer</class>
               <method>hidePrice</method>
             </hideprice_catalog_price_observer>
           </observers>
         </catalog_product_get_final_price>

second event :

<catalog_product_collection_load_after>
  <observers>
    <hprice_catalog_price_observer>
      <type>singleton</type>
      <class>Wsc_Postcode_Model_Observer</class>
      <method>hidePriceCatalog</method>
    </hprice_catalog_price_observer>
  </observers>
</catalog_product_collection_load_after>

simply check if user is not logged in (Observer.php) and set final price equals to zero

public function hidePrice($observer){
            $event = $observer->getEvent();
            $product = $event->getProduct();
            if(!Mage::getSingleton('customer/session')->isLoggedIn()){
                $product->setFinalPrice(0);
                $product->setPrice(0);
            }

    }

    public function hidePriceCatalog($observer){
        $products = $observer->getCollection();

        if(!Mage::getSingleton('customer/session')->isLoggedIn()){
            foreach( $products as $product )
            {
                $product->setFinalPrice(0);
                $product->setPrice(0);
            }
        }
    }

And on phtml we can also check :

if($_product->getFinalPrice() == 0 || $_product->getPrice() == 0){
       echo '<span class="login_for_price"><b>Login to See Price</b><br></span>'; return; }

I hope its work for you.

-1

In Magento version 2 you can disable checkout for guest user from admin panel->store->configuration->sales->checkout.

4
  • questions is magento 1 version
    – Abdul
    Commented Jul 25, 2016 at 11:13
  • You mention magento version in tag also mention in description because now magento 2 is released and developer used magento 2 for development. Commented Jul 26, 2016 at 7:58
  • You can achieve this by doing custom coding. Commented Jul 26, 2016 at 8:37
  • M1 question ...
    – sv3n
    Commented Feb 11 at 0:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.