E-Commerce WordPress Tips & Tricks

How To Set Minimum Cart Amount For User Roles In WooCommerce

Setting a minimum cart amount for certain customers helps protect margins on wholesale and bulk orders. Here is how to set one for user roles in WooCommerce, so different buyers play by the rules that suit your business.

Nirav Mehta Nirav Mehta 5 min read
How To Set Minimum Cart Amount For User Roles In WooCommerce

As a software developer who often deals with support requests of all shapes and sizes, a satisfied client is my ticket to a good night’s sleep. But a loyal and a recurring customer is what makes me get up the next morning and strive harder, learning and bettering myself in the process.

Customer loyalty is sign of confidence that what you’re doing is right, and the people who you’re doing it for, they like and trust your work. And expect you to keep doing it. Shep Hyken was absolutely on point when he said:

customer-loyalty-quote
Image Courtesy: Pinterest

WooCommerce is an exceptional e-commerce platform when it comes to tapping into features that build trust among your customers, and bring returns in the form of recurring customers and of course, more sales.

One way to do this is to price your products differently for customers belonging to varying membership levels or groups, the principle that led to the creation of one of our most successful products. This actually works on two levels:

 

  • Setting low prices for recurring customers ensures more conversions; a customer would be more than happy to buy a product at a much lower price than his peers.
  • Advertising that such a scheme exists on your WooStore acts as an incentive for fresh customers to turn into loyal shoppers and thus avail the low price scheme.

 

Set Minimum Order Amount for User Roles In WooCommerce

As an extension to this practice, you may also want to set different cart value limits for customers belonging to different user roles. This is particularly useful for when your store sells products in wholesale, and you only want to allow a user to go through with the purchase if the order amount exceeds a predefined value.

Minimum-Cart-Amount-Settings2

Conversely, you may let the users of select user roles to purchase products on your store, no matter the order amount.

Here’s how you can map different user roles to a minimum purchase cart amount on WooCommerce.

Step 1: Cart Page Validations:

  • Go to wp-content/plugins/WooCommerce/templates/cart directory and look up for cart-totals.php file
  • Copy this file and go to your theme/child theme, create a folder WooCommerce/cart and paste cart-total.php file here.
  • The structure will be something like /wp-content/themes/{Your-theme-name}/woocommerce/cart/cart-totals.php
  • After copy pasting the file, open the file in the editor and look for the code line:
<div class="wc-proceed-to-checkout">
      <?php do_action( 'woocommerce_proceed_to_checkout' ); ?>
 </div>

 

  • Replace the above code with the lines below.

 

   <div class="wc-proceed-to-checkout"> <?php
   //Get current user and check the user role.

   $current_screen_user = wp_get_current_user();

// In my scenario “wholesale_buyer” is the user role for which I want this validation. You can add your user roles.

    if( in_array( 'wholesale_buyer', $current_screen_user->roles ) ) {

      $minimum = 50; // Set the minimum amt.
      $cart_amt = WC()->cart->subtotal; // cart sub_total, this is actual total excluding discounts and shipping.

                if ( $cart_amt < $minimum ) {
          if( is_cart() ) {
        //Added notices for cart page.
              wc_print_notice(
                  sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
                      wc_price( $minimum ),
                      wc_price( $cart_amt )
                  ), 'error'
              );
          } else {
        //Added notice msg for checkout page.

              wc_add_notice(
                  sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
                      wc_price( $minimum ),
                      wc_price( $cart_amt)
                  ), 'error'
              );
          }
      } else {
          do_action( 'woocommerce_proceed_to_checkout' );
      }
    } else {
      do_action( 'woocommerce_proceed_to_checkout' );
    }
    ?>
   </div>

Step 2: Checkout Page Validations:

From the above code snippet, we hide the Proceed To Checkout button on cart page and add validations on cart page.

For the purpose of fool-proofing, we will also have to add the validations on checkout page, since a users with a little technical background could simply type in the URL of the page and bypass validations.

To do this, place the below code snippet in your themes ->  functions.php file.

 

<?php
add_action( 'woocommerce_checkout_process', 'wdm_wu_minimum_order_amount' );

function wdm_wu_minimum_order_amount() {

    $current_screen_user = wp_get_current_user();
    if( in_array( 'wholesale_buyer', $current_screen_user->roles ) ) {

      $minimum = 50;

    if ( WC()->cart->subtotal < $minimum ) {
       if( is_cart() ) {
           wc_print_notice(
               sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,

                   wc_price( $minimum ),
                   wc_price( WC()->cart->subtotal )
               ), 'error'
           );

       } else {
           wc_add_notice(
               sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,

                   wc_price( $minimum ),
                   wc_price( WC()->cart->subtotal )

               ), 'error'
           );
       } } } }

 

And that’s about it. Every user belonging to the specified user role will now be restricted to a minimum cart value while shopping on your website. Here’s how it would look in practice:

 

woocommerce-minimum-cart-amount

 

What’s amazing is that this needs not be limited to a single user role; play around with the code a bit and you can assign a minimum cart limit, and even create a settings page on the back end that would let you map user roles to minimum cart limits.


Found this article helpful? Let us know in the comment section below. Your feedback is what keeps us going. :)

 

 

Get a FREE Consultation

Let's build something that lasts.

Share what's on your mind — a clear brief, a half-formed idea, or just a sense that something needs to change. We'll listen first, ask the right questions, and point you toward what's actually worth building.

We take on a handful of projects each quarter,ones where we can truly make a difference.

  • Receive a human response within 24 hours
  • Get a detailed scope and quote upfront
  • We're happy to sign an NDA upon request

    Free 30-Min Strategy Call

    Your Name *

    Your Phone No *

    Work Email *

    Your Budget*

    Project Details *