A Guide to WooCommerce Min Purchase Amount for Specific Product

In e-commerce business, you wish to set Min purchase amount for specific product. As in case if you do not decide minimum order quantity, you incur losses. So, sometimes, it’s wise to learn about the following. That is how to set WooCommerce Min Purchase Amount for specific product or cart pages! 

Being a developer, you must know how to enable this functionality in your store. So that the website visitors will come to know regarding this minimum purchase criteria. Let’s see how you can do it.

In our example, let’s assume we have to set the minimum order amount for product ABC to $50. So, once this functionality is enabled, the add to cart quantity will not begin with 1. 

Instead of which, it reflects “$50 divided by product price” every time someone adds products to it. For example, when the product price is $10, your customer has to add a minimum 5 quantities. So, the $50 minimum criteria will meet. 

Let’s see how to do it.

Image showing WooCommerce Min Purchase amount for product & cart page

PHP Snippet: Set Min Purchase Amount for Specific Product @ WooCommerce Single Product pages & Cart Pages

Further, we will set the minimum order amount for product ID = 123 of $50. The below function is applicable to both product & cart pages. If product ID = 123 price is $9, then the minimum amount will be ceil(50/9) = 6. 

// 1. Single Product Page
 
add_filter( 'woocommerce_quantity_input_min', 'phpsof_woocommerce_quantity_min_50_eur', 9999, 2 );
   
function phpsof_woocommerce_quantity_min_50_eur( $min, $product ) {  
 
   if ( is_product() ) {
// 123 will be your static product id
      if ( 123 === $product->get_id() ) {
         $min = ceil( 50 / $product->get_price() );
      }
 
   }
    
   return $min;
 
}
 
// ------------
// 2. Cart Page
 
add_filter( 'woocommerce_cart_item_quantity', 'phpsof_woocommerce_quantity_min_50_eur_cart', 9999, 3 );
   
function phpsof_woocommerce_quantity_min_50_eur_cart( $product_quantity, $cart_item_key, $cart_item ) {  
    
   $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
    
   $min = 0;
 // 123 will be your static product id
   if ( 123 === $_product->get_id() ) {
      $min = ceil( 50 / $_product->get_price() );
   }
    
   $product_quantity = woocommerce_quantity_input( array(
      'input_name'   => "cart[{$cart_item_key}][qty]",
      'input_value'  => $cart_item['quantity'],
      'max_value'    => $_product->get_max_purchase_quantity(),
      'min_value'    => $min,
      'product_name' => $_product->get_name(),
   ), $_product, false );
    
   return $product_quantity;
 
}

Where do you add this snippet?

So, you can add this PHP snippet at your child theme function.php file’s bottom. It should be placed before “?>”, if you have it there. Apart from this, CSS goes in your child theme style.css file. 

Is this snippet still valid?  

So, enable this WooCommerce Min Purchase Amount for specific product function. I have applied this code on the Storefront theme and WordPress friendly hosting PHP 7.3. Let me know if everything works as expected. Share it further if this snippet has saved your time.  

Also Read, WooCommerce Product Category Dropdown Widget

WooCommerce Set Product Price Programmatically

Important links: WooCommerce Storefront – https://woocommerce.com/storefront/