woocommerce Min/Max quantity and total price custom code through function.php

0 0
Read Time:1 Minute, 36 Second

In WordPress woocommerce, there is no such functionality to set up the Min/max quantity and total price of Cart, So that customers can meet up with one of the conditions and be able to make the checkout on the eCommerce platform.

Here is the solution where you can make your customer restrict to checkout without meeting up your store conditions.

You can get to the file either using a server or FTP connect.

Make child theme under the wp-content > themes > your-child-theme

Find function.php under the child theme and open it in any code editor.

Copy and paste this code into your child’s theme.

<?php 

	add_action( 'woocommerce_check_cart_items', 'blogsprdp_set_min_total' );
	function blogsprdp_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 = 250;

	// Set minimum cart quanity

	$minimum_num_products = 5;

	$cart_num_products = WC()->cart->cart_contents_count;

	$total = WC()->cart->subtotal;

	// A Minimum of 250 currency of store or A  minimum 5 quantity of items is required before checking out. 

	// any of the condition match it will redirect to the checkout page.


	if( ($total <= $minimum_cart_total) && ($cart_num_products < $minimum_num_products)   ) {
		
		// Display our error message
		wc_add_notice( sprintf( '<strong>Before checkout please make sure you have minimum 5 item in cart or total of cart is more than 250$</strong>',
							   $minimum_num_products,
							   $cart_num_products ),
					  'error' );
	}
	}
	}

?>

Checkout your cart part customer will not be able to checkout till any one condition will be matched up here.

You can find the code GitHub

git clone https://github.com/pradeepsingh37/Woocommerce-Min-Max-quantity-and-total-price-custom-code-through-function.php.git

Follow and subscribe to us on youtube and facebook.

You can find videos on youtube https://youtu.be/Xg9mLGKqd

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %