If you want to restrict customer to checkout based on your criteria (condition), then this article is your answer.
For example if you want to restrict customer when cart total less then $300, this method is worth to give a try.
Here we are using Magemonkeys as Vendor name and CheckoutRestriction as the name of a module. You can change this according to your Vendor and Module name.
Step 1: Create Registration
Create registration.php file in the app/code/Magemonkeys/CheckoutRestriction folder with the following code.
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Magemonkeys_CheckoutRestriction',
__DIR__
);
Step 2: Create a module
Create a module.xml file in the app/code/Magemonkeys/CheckoutRestriction/etc folder with the following code.
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magemonkeys_CheckoutRestriction" setup_version="1.0.0">
<sequence>
<module name="Magento_Checkout"/>
</sequence>
</module>
</config>
Step 3: Create a di.xml for front-end
Create a di.xml file in the app/code/Magemonkeys/CheckoutRestriction/etc/frontend folder with the following code.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
// plugin restrict checkout
<type name="MagentoCheckoutControllerIndexIndex">
<plugin name="restrictcheckout" type="MagemonkeysCheckoutRestrictionPluginCheckoutControllerRestrict"/>
</type>
</config>
Step 4: Create a Plugin file
Create a Restrict.php file in the app/code/Magemonkeys/CheckoutRestriction/Plugin/Checkout/Controller with the following code.
<?php
namespace MagemonkeysCheckoutRestrictionPluginCheckoutController;
use MagentoFrameworkControllerResultRedirectFactory;
use MagentoFrameworkMessageManagerInterface;
use MagentoFrameworkUrlFactory;
use MagentoCheckoutControllerIndexIndex;
use MagentoCheckoutModelCart;
class Restrict
{
private $urlModel;
private $resultRedirectFactory;
private $messageManager;
public function __construct(
UrlFactory $urlFactory,
RedirectFactory $redirectFactory,
ManagerInterface $messageManager,
Cart $cart
) {
$this->urlModel = $urlFactory;
$this->resultRedirectFactory = $redirectFactory;
$this->messageManager = $messageManager;
$this->cart = $cart;
}
public function aroundExecute(
Index $subject,
Closure $proceed
) {
$this->urlModel = $this->urlModel->create();
//add your logic here
$subTotal = $this->cart->getQuote()->getSubtotal();
if(!empty($subTotal) && $subTotal < 300){
$this->messageManager->addErrorMessage(__("Unable to checkout as one or more products have not met their minimum purchase theshold."));
$defaultUrl = $this->urlModel->getUrl('checkout/cart/', ['_secure' => true]);
$resultRedirect = $this->resultRedirectFactory->create();
return $resultRedirect->setUrl($defaultUrl);
}
return $proceed();
}
}
Here is screenshot which shows error message when some one trying to click on checkout and subtotal less then $300

You can replace 300$ with your favorable amount and use accordingly.

