Magento – Show cash on delivery option to registered users only

cash-on-deliveryonepage-checkout

i want to show cash on delivery method during checkout, only for registered users.
if user is logged in show cash on delivery method otherwise not.

Please suggest in which file should i make the edit

Best Answer

You can use the event payment_method_is_active.
Create an observer on that and you will get the payment method instance as a parameter.
Check if the customer is logged in deactivate it if it's not.
Something like this:

public function paymentMethodIsActive($observer) {
    $method = $observer->getEvent()->getMehodInstance();
    $result = $observer->getEvent()->getResult();
    if (!$result->isAvailable) { //if the method is not available at all, do nothing
        return $this;
    }
    if ($method->getCode() == 'cashondelivery') { //if method is cache on delivery
        //make it available only if the customer is logged in
        $result->isAvailable = Mage::getSingleton('customer/session')->isLoggedIn();
    }
}

More info about the event observers can be found here

Related Topic