magento disable proceed to checkout until condition is true

magento disable proceed to checkout until condition is true

September 3, 2026 · Illustrated author avatarBy Stefan Bogdanescu
magento disable proceed to checkout until condition is true

Controlling Checkout Access: Enforcing Minimum Cart Quantity in Magento

As an experienced e-commerce developer, I often encounter scenarios where we need to restrict certain functionalities based on specific conditions. One common requirement is to prevent customers from proceeding to checkout until their cart meets a minimum threshold, such as having at least two products. In this post, we’ll explore how to achieve this using Magento’s built-in features and best practices.

Understanding the Checkout Process in Magento

Before diving into the code, it’s essential to understand how the checkout process works in Magento. When a customer clicks the “Proceed to Checkout” button, Magento triggers the checkout_cart_index controller action, which is responsible for initializing the checkout process.

Disabling the Check-out Button Until Conditions are Met

To disable the check-out button until a certain condition (for example, having at least two products in the cart), we need to override the default behavior of the checkout_cart_index controller and add our custom logic. Here’s how you can do it:

  1. Create an extension attribute set and module if you haven’t already.
  2. Override the Magento_Checkout\Controller\Cart\Index class or create a plugin.

For this example, let’s assume we have created a plugin using the Magento 2 Plugin system. You need to create a file named di.xml in your custom module configuration folder:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Controller\Cart\Index">
        <plugin name="Disable_Proceed_to_Checkout_Based_on_Cart_Count"
                type="Vendor\ModuleName\Controller\Plugin\DisableProceedToCheckout" />
    </type>
</config>
  1. Create the plugin class: Vendor/ModuleName/Controller/Plugin/DisableProceedToCheckout.php.
<?php

namespace Vendor\ModuleName\Controller\Plugin;

use Magento\Framework\App\Http\Context;
use Magento\Quote\Model\QuoteRepository;

class DisableProceedToCheckout
{
    private $context;
    private $quoteRepository;

    public function __construct(
        Context $context,
        QuoteRepository $quoteRepository
    ) {
        $this->context = $context;
        $this->quoteRepository = $quoteRepository;
    }

    public function beforeExecute(): void
    {
        $quoteId = $this->context->getQuote()->getId();
        if (!$quoteId) {
            return;
        }

        $quote = $this->quoteRepository->get($quoteId);
        if ($quote->getItemsCount() < 2) {
            $this->context->setFlag(Context::FLAG_NO_DISPATCH, true);
            throw new \Magento\Framework\Exception\LocalizedException(__('Please add at least two products to your cart before proceeding to checkout.'));
        }
    }
}

This plugin checks if the cart contains fewer than two items. If so, it sets a flag and throws an exception, preventing the controller from executing further.

Other Considerations

  • Make sure you have the necessary permissions set for your custom module.
  • Test this functionality thoroughly in various scenarios to ensure it works as expected.
  • You can customize the minimum cart quantity by modifying the condition inside the beforeExecute method.

Conclusion and Further Reading

Disabling the “Proceed to Checkout” button until a certain condition is met requires a good understanding of Magento’s checkout process and its plugin system. By following this approach, you can effectively control when customers can proceed through the checkout workflow based on your specific business requirements. For more advanced customizations or detailed explanations of the Magento 2 plugin system, I recommend visiting our Magento Development Guide at LaravelCompany.

Happy coding! Let me know if you have any further questions or need assistance with other Magento development challenges.

Magento 2 Checkout Catalog API

Our network