• Using Woocommerce? Out of the box, it does let you set maximum quantities for your products, but it still has its limits. For instance, it doesn’t let your customers know what the max quantity is or hide the quantity box if you wish to hide the quantity box if your max quantity is set to one. Yes, I know that if you check the “sold individually” checkbox it will do just that, but it won’t let you order any more of that item separately. For me, this scenario occurs with Product Bundles where specific options are unique to each ordered quantity. I want my customers to be able to order more than one with separate specifics for each. For example: A business card bundle pack where the details are unique. By default if you order multiples of each bundle, you don’t get the chance to enter the unique values for each card set.

    Now….if there were a plugin that allows you to add a new variation where a separate variation form appears so you can enter the unique data again…that’d be great…but I don’t think there is one. Would also be great if the ticker stopped going up when the set maximum quantity is reached. If I find a way to do so, I’ll mod the code below to reflect that.

    The following code will assist you in letting your customers know what the max quantity is for your product and will let you hide the quantity ticker if the max quantity is set to 1. You of course can easily modify this to suit your theme and product type use.

    // display max quantity allowed if set on single product page
    add_action('woocommerce_single_product_summary', 'maxquantityallowed', 30);
    function maxquantityallowed() {
    if(get_post_meta( get_the_ID(), 'maximum_allowed_quantity', true ) ){
        echo 'Maximum quantity allowed for this product is <strong>'. get_post_meta( get_the_ID(), 'maximum_allowed_quantity', true ) .'</strong>.  Request a custom quote for bulk orders.'; }
    }
    
    // hide quantity box if max quantity is set to one
    add_action('wp_head','hide_quantity_counter');
    function hide_quantity_counter() {
    global $product;
    $product = new WC_Product( get_the_ID() );
    $productcount = get_post_meta( get_the_ID(), 'maximum_allowed_quantity', true );
    if (($product->is_type( 'bundle' )) || $productcount == 1) { echo '<style> div.bundled_item_cart_content div.bundle_button div.quantity {display:none!important;} </style>'; }
    if (($product->is_type( 'simple' )) || $productcount == 1) { echo '<style> div.quantity {display:none!important;} div.bundled_product div.quantity {display:inherit!important;} </style>'; }
    if (($product->is_type( 'variable' )) || $productcount == 1) { echo '<style> div.variations_button div.quantity {display:none!important;} div.bundled_product div.variations_button div.quantity {display:inherit!important;} </style>'; }
    }
  • The topic ‘TIP – Woocommerce max quantities.’ is closed to new replies.