Want to have complete control over customers’ checkout? Most often, Magento 2 store owners require to restrict customers’ purchase at the checkout by adding the conditions that are required to be fulfilled by them.
It is quite common for the store owners to restrict Magento 2 checkout based on various conditions like:
- Minimum order amount required for the specific customer groups
- Sign up and login conditions for particular products. Eg: Sample Products
- Limit cart quantity for specific conditions. Eg: limit cart quantity based on category or customer
- Location Criteria
If you too want to try one of these conditions on the checkout of your Magento 2 store to increase the average order amount, encourage customers to upgrade their membership, ease the delivery process, etc. you may try the below method to restrict Magento 2 checkout based on various conditions.
For example, you want to restrict a customer to checkout with a sample product that can be bought only once. On his/her second attempt, restrict the checkout with the below code!
You may also set the conditions to limit the cart quantity based on the product quantity ordered from each category for every customer group.
Method to Restrict Magento 2 Checkout Based on Various Conditions:
Implement the below code at app\code\Vendor\Extension\etc\frontend\di.xml
<plugin name="restrictcheckout" type="Vendor\Extension\Plugin\Checkout\Controller\Restrict"/>
Implement the below code at app\code\Vendor\Extension\Plugin\Checkout\Controller\Restrict.php
public function __construct(
$this->urlModel = $urlFactory;
$this->resultRedirectFactory = $redirectFactory;
$this->messageManager = $messageManager;
public function aroundExecute(
$this->urlModel = $this->urlModel->create();
// code for redirect to cart page with error message
//$defaultUrl = $this->urlModel->getUrl('checkout/cart/', ['_secure' => true]);
//$resultRedirect = $this->resultRedirectFactory->create();
With the above methods, you can tweak and twist the checkout conditions in Magento 2 store!
Please feel free to post any doubts in the Comments section below!
Do rate the post with 5 stars.
Get Weekly Updates
Never miss Magento tips, tricks, tutorials, and news.
Thank you for subscribing.
Something went wrong.