-1

I am building a wholesale store with wordpress and woocommerce and having a strange problem with the requirement.

The client wants to sell the products in multiple of 6 like 6/12/18/24, so when a user reach product page , he can select 6/12/18/24 as product quantity.

I have tried variation of product but the problem is this will hide the orignal price of product and will show the price of 6 products at least.

For example: I have created variations for a product priced at 1$ with multiples of 6 and then it will show the price as "from 6$" rather than orignal price of product and its seems too much work to add variations in 500+ products manually.

How to add only multiples of 6 in the add to cart quantity selection?

1

In the bleeding edge of WooCommerce 2.1 you can filter woocommerce_quantity_input_min and woocommerce_quantity_input_step directly. That should get you 6,12,18, etc. I have no idea if these filters are in WC2.0.?. Note the $product object is passed to the filter in case you don't want this to be a universal change. You can get the bleeding edge of WooCommerce from github, though it probably isn't advisable to use it in production yet.

function wpa116693_filter_min_quantity( $min, $product ){
    return 6;
}
add_filter( 'woocommerce_quantity_input_min', 'wpa116693_filter_min_quantity', 10, 2 );

function wpa116693_filter_quantity_step( $step, $product ){
    return 6;
}
add_filter( 'woocommerce_quantity_input_step', 'wpa116693_filter_quantity_step', 10, 2 );
  • The filters you are using are there in WC2.0, additionally there is woocommerce_quantity_input_max. The filter woocommerce_quantity_input_args pretty much bundles those - woocommerce_quantity_input() in source. @user2844394 – Nicolai Oct 8 '13 at 15:21
  • I just realized that it's working just fine, with both methods - singular or combined filter - but only for simple products. Before I just tried it on a variable product and there seems to be some interference with the add-to-cart-variation.js, causing the unwanted behaviour. @user2844394 – Nicolai Oct 8 '13 at 15:33
  • That's odd, because the quantity.php template is the same for all product types. – helgatheviking Oct 8 '13 at 23:00
0

I had to look into that problem once, but the decision at the end was to sell in packages of 8, I never really had to solve the problem. Maybe that would be the easiest solution anyways?

I stumbled over a question on stackoverflow https://stackoverflow.com/a/17762213/2505105 explaining how to do it:

add_filter( 'woocommerce_quantity_input_args', 'pkg_wc_quantity_input_args', 10, 2 );
function pkg_wc_quantity_input_args( $args, $product ) {
    $args['input_value'] = 8;
    $args['max_value'] = 64;
    $args['min_value'] = 8;
    $args['step'] = 8;
    return $args;
}

The guy who wrote answer added a little bit more information, so best would be to go there yourself. But before you get all excited, this isn't working perfectly.


Update:

This method just as well as the one that @helgatheviking suggested is working, but only for simple products. The problem remains for variable products, see my comments at @helgatheviking's answer. In addition this does not take care of the quantity input inside the cart.


2nd Update:

Cleaning up I found this code again, it concerns implementing the steps on the cart page, for this you have to use $_product.

function wpse116693_filter_min_quantity_cart( $min, $_product ){
    return 6;
}
add_filter( 'woocommerce_quantity_input_min', 'wpse116693_filter_min_quantity_cart', 10, 2 );

function wpse116693_filter_quantity_step_cart( $step, $_product ){
    return 6;
}
add_filter( 'woocommerce_quantity_input_step', 'wpse116693_filter_quantity_step_cart', 10, 2 );
  • thanks for the amswer mate , i will test this and report my results here min and max quantity plugin cant do what i need exactly , it can only limit products but i want multiples as well lol , and i got excited – user2844394 Oct 3 '13 at 22:58
  • OK , Now here is how achieved this there are 3 places where i want to replace the settings to take 6 as min value and rest provide multiples of 6 for rest of quantity values 1. product page – user2844394 Oct 4 '13 at 19:04
0

That is a good solution but it wont' work with variable products because those products input values are overridden using javascript. I spent a while putting a plugin together that now supports variable products that would be worth a try. It allows you to set minimum / maximum / step values for products and is pretty easy to use.

WooCommerce Advanced Product Quantities

http://wordpress.org/plugins/woocommerce-incremental-product-quantities/

0

I found your question when I was on some sort of same kind of mission. At least in WooCommerce 3+ there are 2 ways needed to adjust the input number for products:

// Add quantity limit for simple products & on cart page
add_filter( 'woocommerce_quantity_input_args', my_woocommerce_max_quantity', 10, 2 );
function my_woocommerce_max_quantity( $args, $product ) {
    $args['max_value'] = 10; // Max quantity
    return $args;
}

// Add quantity limit for variable products
add_filter( 'woocommerce_available_variation', 'my_woocommerce_max_quantity_variations' );
function my_woocommerce_max_quantity_variations( $args ) {
    $args['max_qty'] = 10;      // Max quantity
    return $args;
}

Now you have full control over the input arguments you could add the $args['....'] into your functionlets say:

$args['input_value'] = 1;   // Starting value
$args['max_value'] = 10;    // Maximum value
$args['min_value'] = 1;   // Minimum value
$args['step']    = 6;   // Quantity steps

It's an old topic but still, maybe this could still be used by someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.