0

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

1 Answer 1

1

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

4
  • can this be achieved by using shopping cart price rules?
    – sonal
    Oct 9, 2014 at 6:52
  • @sonal. No. The shopping cart price rules are there to change the product prices or give discounts depending on the conditions you set. It cannot enable or disable payment or shipping methods.
    – Marius
    Oct 9, 2014 at 7:09
  • can u please elaborate how to accomplish the solution you have mentioned?
    – sonal
    Oct 9, 2014 at 9:30
  • I just did. What more do you want? I gave you the code for the observer and a link that shows you how to add an observer.
    – Marius
    Oct 9, 2014 at 10:20

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.