How To

How to Display Minimum Order Amount Message on Minicart in Magento 2?

Hello Magento Friends,

In today’s blog, I will provide the steps for displaying the minimum order amount message on minicart in Magento 2.

As an e-commerce store owner, ensuring your customers are aware of the minimum order amount is crucial for a smooth shopping experience. Magento 2 allows you to set a minimum order amount to encourage customers to add more products and increase their average order value.

By default, however, this minimum requirement isn’t displayed on the minicart, leaving customers confused if their order doesn’t process. By displaying this information directly on the minicart, you can help customers quickly understand the requirements before proceeding to checkout.

Let’s go through the steps to display a minimum order amount message on the minicart in Magento 2.

Steps to Display Minimum Order Amount Message on Minicart in Magento 2:

Step 1: Create “di.xml” file inside the Extension etc folder.

app\code\Vendor\Extension\etc\frontend\

Now add the below code

<?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\CustomerData\Cart">
  <plugin name="custom_minicart_content" type="Vendor\Extension\Plugin\CustomerData\Cart"/>
 </type>
</config>

Step 2: Now, create “Cart.php” file inside the Extension Plugin folder.

app\code\Vendor\Extension\Plugin\CustomerData\

Then include the code given below

<?php
namespace Vendor\Extension\Plugin\CustomerData;

use Magento\Checkout\Helper\Cart as cartHelper;
use Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage;

class Cart
{
    /**
     * @var cartHelper
     *
     */    protected cartHelper $cartHelper;

    /**
     * @var ValidationMessage
     */    protected ValidationMessage $minOrderValidationMessage;

    /**
     * Constructor method
     *
     * @param ValidationMessage $minOrderValidationMessage
     * @param cartHelper $cartHelper
     */    public function __construct(
        ValidationMessage $minOrderValidationMessage,
        cartHelper $cartHelper
    ) {
        $this->minOrderValidationMessage = $minOrderValidationMessage;
        $this->cartHelper = $cartHelper;
    }

    /**
     * Constructor method
     *
     * @param \Magento\Checkout\CustomerData\Cart $subject
     * @param array $result
     * @return array
     */    public function afterGetSectionData(\Magento\Checkout\CustomerData\Cart $subject, array $result)
    {
        $result['min_order_message'] = '';
        if (!$this->cartHelper->getQuote()->validateMinimumAmount()) {
            $result['min_order_message'] = $this->minOrderValidationMessage->getMessage();
        }
        return $result;
    }
}

Step 3: To override content.html file we need to create requirejs-config.js file inside Extension View folder.

app\code\Vendor\Extension\view\frontend\

And add the code as follows

var config = {
    map: {
        '*': {
            'Magento_Checkout/template/minicart/content.html':
            'Vendor_Extension/template/minicart/content.html'
        }
    }
}

Step 4: Copy vendor\magento\module-checkout\view\frontend\web\template\minicart\content.html file and paste it at app\code\Vendor\Extension\view\frontend\web\template\minicart\

Now, add the below code in the content.html file wherever you want to display the minimum order amount message.

<!-- ko if: getCartParam('summary_count') > 0 && getCartParam('min_order_message') != '' -->
<div class="message message-notice notice">
    <span class="min_order_config" text="getCartParam('min_order_message')"></span>
</div>
<!--/ko-->

Step 5: Make sure you’ve enabled the below configuration and set the minimum order amount as per your requirement. Please review the below screenshot for your reference.

Stores > Configuration > Sales > Sales > Minimum Order Amount 

Output:

Conclusion:

By following these steps, you can display a minimum order amount message on the minicart in Magento 2. This customization enhances the user experience by clearly communicating order requirements, helping to prevent confusion and frustration during the checkout process.

Share the solution with your other Magento friends and stay in touch with us for more.

Happy Coding!

Click to rate this post!
[Total: 0 Average: 0]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate ?️ Certified Magento Developer?‍?. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.?

Recent Posts

How to Use Laravel Eloquent WHEREIN Query?

The Laravel Eloquent ORM provides a powerful way to interact with your database concisely and…

4 days ago

WooCommerce vs Shopify: A Detailed Comparison for 2024

WooCommerce vs Shopify: A Detailed Comparison for 2024 Choosing the right e-commerce platform is critical…

5 days ago

How to Create an Effective SEO Strategy

In today’s digital landscape, having a strong online presence is paramount for businesses and content…

5 days ago

Google Launches June 2024 Spam Update

Google's search results are constantly evolving, and a key part of that evolution is keeping…

5 days ago

How to Get Products Upto 250 Without Pagination in Shopify Remix App?

In this blog post, we'll show you how to get products upto 250 without pagination…

5 days ago

Shopify Editions Summer ’24: Everything You Need To Know

The wait is over, and Shopify Editions Summer '24 has arrived, bringing with it a…

5 days ago