• Hello,

    Is there a way for me to display a message saying “Max quantity reached” or “Sorry we do not have enough quantity in stock”?

    In Cart, when user tries to click the “+” button, nothing changes. I’d like to display an error message to inform the user that they cannot exceed that number.

    I’ve had a look through the code and this feature is there, but does not seem to be working. Stock management feature is enabled for all products.

    I do not want to enable backorders, nor do I want to set max/min levels manually.

    // We only need to check products managing stock, with a limited stock qty.
    			if ( ! $product->managing_stock() || $product->backorders_allowed() ) {
    				continue;
    			}
    
    			// Check stock based on all items in the cart and consider any held stock within pending orders.
    			$held_stock     = ( $hold_stock_minutes > 0 ) ? wc_get_held_stock_quantity( $product, $current_session_order_id ) : 0;
    			$required_stock = $product_qty_in_cart[ $product->get_stock_managed_by_id() ];
    
    			if ( $product->get_stock_quantity() < ( $held_stock + $required_stock ) ) {
    				/* translators: 1: product name 2: quantity in stock */
    				$error->add( 'out-of-stock', sprintf( __( 'Sorry, we do not have enough "%1$s" in stock to fulfill your order (%2$s available). We apologize for any inconvenience caused.', 'woocommerce' ), $product->get_name(), wc_format_stock_quantity_for_display( $product->get_stock_quantity() - $held_stock, $product ) ) );
    				return $error;
    			}
    		}
    
    		return true;
    	}
Viewing 2 replies - 1 through 2 (of 2 total)
  • Phil

    (@fullysupportedphil)

    Automattic Happiness Engineer

    @myfakename, I’m not sure I understand your situation.

    If the product should only be purchased individually, then you can turn on the “Sold Individually” option under the Inventory tab.

    It you want to sell the product in fixed groups, I’d recommend something like the Min/Max Quantities plugin.

    Thread Starter myfakename

    (@myfakename)

    Hi @fullysupportedphil ??

    The product is purchased individually. What I’m trying to achieve is within the Cart page. If the customer tries to increase the quantity from the Cart page, but I don’t have enough stock, I want it to display a message to say “Not enough stock available” or something along those lines.

    Cart Page:
    Customer tries to change quantity to = 3
    Stock available = 2
    Display message = “Sorry, you have reached maximum available quantity”

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to enable Out of Stock message when quantity input exceeds stock levels?’ is closed to new replies.