This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

📣 Try the fastest hosting platform with pay-as-you-go pricing & 24/7 expert support! MIGRATE NOW →

How to Set Purchase Limits on Your WooCommerce Cart

Updated on August 24, 2021

2 Min Read

WooCommerce offers several ways of setting the parameters  for WooCommerce purchase limit. Although the steps are different, the outcome is often identical. However, I consider the following steps to be very effective. I  will use the woocommerce_check_cart_items action provided by WooCommerce to run the functions and execute the code.  

Banner

Setting a Minimum Weight Requirement For WooCommerce Purchase Limit

Many stores often do not allow their customers to checkout until the weight of the purchase does not exceed a pre-set limit. Minimum weight requirements significantly reduce delivery costs and the process becomes more streamlined. Bear in mind that all weight calculations are carried out in weight units set under WooCommerce – > Settings – > Products.

Place the following code in the functions.php, located in the theme folder.

add_action( 'woocommerce_check_cart_items', 'cldws_set_weight_requirements' );
function cldws_set_weight_requirements() {
	// Only run in the Cart or Checkout pages
	if( is_cart() || is_checkout() ) {
		global $woocommerce;
		// Set the minimum weight before checking out
		$minimum_weight = 30;
		// Get the Cart's content total weight
		$cart_contents_weight = WC()->cart->cart_contents_weight;
		// Compare values and add an error is Cart's total weight
		if( $cart_contents_weight < $minimum_weight  ) {
			// Display our error message
			wc_add_notice( sprintf('<strong>A Minimum Weight of %s%s is required before checking out.</strong>'
				. '<br />Current cart weight: %s%s',
				$minimum_weight,
				get_option( 'woocommerce_weight_unit' ),
				$cart_contents_weight,
				get_option( 'woocommerce_weight_unit' ),
				get_permalink( wc_get_page_id( 'shop' ) )
				),
			'error'	);
		}
	}
}

Set Purchase Limits on WooCommerce

Setting a Minimum Dollar Amount per Order

A minimum dollar amount is another important restriction on the store. Minimum dollar amounts are often used to keep all transactions at a common base value per transaction. To set this limit,  use the following code

add_action( 'woocommerce_check_cart_items', 'cldws_set_min_total');
function cldws_set_min_total() {
	// Only run in the Cart or Checkout pages
	if( is_cart() || is_checkout() ) {
		global $woocommerce;
		// Set minimum cart total
		$minimum_cart_total = 100;
        // A Minimum of 100 AUD is required before checking out.

		$total = WC()->cart->subtotal;
        // Compare values and add an error is Cart's total
	    if( $total <= $minimum_cart_total  ) {
       	// Display our error message
			wc_add_notice( sprintf( '<strong>A Minimum of %s %s is required before checking out.</strong>'
				.'<br />Current cart\'s total: %s %s',
				$minimum_cart_total,
				get_option( 'woocommerce_currency'),
				$total,
				get_option( 'woocommerce_currency') ),
			'error' );
		}
	}
}

min amountConclusion

WooCommerce permits you to utilize actions and filters to change the ordinary checkout process. I hope that you will implement these two limits to your WooCommerce store. If you need clarification or wish to contribute to the discussion, please leave a comment below.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Owais Alam

is the WordPress Community Manager at Cloudways - A Managed WooCommerce Hosting Platform and a seasoned PHP developer. He loves to develop all sorts of websites on WordPress and is in love with WooCommerce in particular. You can email him at [email protected]

×

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour

CYBER WEEK SAVINGS

  • 0

    Days

  • 0

    Hours

  • 0

    Mints

  • 0

    Sec

GET OFFER

For 4 Months &
40 Free Migrations

For 4 Months &
40 Free Migrations

Upgrade Now