0

Is it possible to prevent a customer (under some circumstances) from checking out? I know it is possible to disable checkout from System >> Configuration >> Sales >> Checkout >> Checkout Options >> Disable Onepage Checkout.

I want to know if there's a way to disable checkout for a particular customer.

1 Answer 1

2

Try below code:

app/etc/module/Supravatm_DisableCheckout.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Supravatm_DisableCheckout>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Checkout/>
            </depends>
        </Supravatm_DisableCheckout>
    </modules>
</config>

app/code/local/DisableCheckout/etc/config.xml

<?xml version="1.0" ?>
<config>
    <modules>
        <Supravatm_DisableCheckout>
            <version>1.0.0</version>
        </Supravatm_DisableCheckout>
    </modules>
    <global>
        <events>
            <controller_action_predispatch_checkout_cart_index>
                <observers>
                    <Supravatm_DisableCheckout_Model_Observer>
                        <type>singleton</type>
                        <class>Supravatm_DisableCheckout_Model_Observer</class>
                        <method>disableCheckoutButton</method>
                    </Supravatm_DisableCheckout_Model_Observer>
                </observers>
            </controller_action_predispatch_checkout_cart_index>
        </events>
    </global>
</config>

app/code/local/DisableCheckout/Model/Observer.php

<?php 
class Supravatm_DisableCheckout_Model_Observer {

    public function disableCheckoutButton(Varien_Event_Observer $observer) {

        // Check if any customer is logged in or not
        if (Mage::getSingleton('customer/session')->isLoggedIn()) {

            //Load the customer's data
            $customer = Mage::getSingleton('customer/session')->getCustomer();
            if($customer->getEmail() == 'specify customer email') {
                $quote = Mage::getSingleton('checkout/session')->getQuote();
                //$quote->setHasError(true);
            }
        }
        return $this;
    }
}
?>

Alternate Process:

In your theme, edit the template file

checkout/onepage/link.phtml

there is code

<?php if ($this->isPossibleOnepageCheckout()):?>
    <button type="button" title="<?php echo $this->__('Proceed to Checkout') ?>" class="button btn-proceed-checkout btn-checkout<?php if ($this->isDisabled()):?> no-checkout<?php endif; ?>"<?php if ($this->isDisabled()):?> disabled="disabled"<?php endif; ?> onclick="window.location='<?php echo $this->getCheckoutUrl() ?>';"><span><span><?php echo $this->__('Proceed to Checkout') ?></span></span></button>
<?php endif?>

Alternative :

You will find this function isPossibleOnepageCheckout() in

Mage/Checkout/Block/Onepage/Link.php

You can extend this class and add your custom logic by which you can hide the checkout button.

Also in /Mage/Checkout/controllers/OnepageController.php

in indexAction()

write your condition so that user is redirected to cart page if condition is not fulfilled

2
  • 1
    Thanks. I changed controller_action_predispatch_checkout_cart_index to controller_action_predispatch to disable the checkout in every page, including direct access to checkout/onepage. Nov 2, 2017 at 9:09
  • that is make sense Nov 2, 2017 at 12:17

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.