Skip to content

Instantly share code, notes, and snippets.

@jameskoster
Last active March 8, 2021 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jameskoster/6061298 to your computer and use it in GitHub Desktop.
Save jameskoster/6061298 to your computer and use it in GitHub Desktop.
WooCommerce - Adjust the quantity incrementer
// Simple products
add_filter( 'woocommerce_quantity_input_args', 'jk_woocommerce_quantity_input_args', 10, 2 );
function jk_woocommerce_quantity_input_args( $args, $product ) {
$args['input_value'] = 2; // Starting value
$args['max_value'] = 80; // Maximum value
$args['min_value'] = 2; // Minimum value
$args['step'] = 2; // Quantity steps
return $args;
}
// Variations
add_filter( 'woocommerce_available_variation', 'jk_woocommerce_available_variation' );
function jk_woocommerce_available_variation( $args ) {
$args['max_qty'] = 80; // Maximum value (variations)
$args['min_qty'] = 2; // Minimum value (variations)
return $args;
}
@emilysnothere
Copy link

Thanks for this, I've set the default value displayed to '0' which works perfectly, except it overrides the quantity displaying in the cart to '0' (even though prices are correct).

Any fix for this?

// Simple products
add_filter( 'woocommerce_quantity_input_args', 'jk_woocommerce_quantity_input_args', 10, 2 );
function jk_woocommerce_quantity_input_args( $args, $product ) {
$args['input_value'] = 0; // Starting value
return $args;
}
// Variations
add_filter( 'woocommerce_available_variation', 'jk_woocommerce_available_variation' );
function jk_woocommerce_available_variation( $args ) {
 $args['input_value']   = 0;    // Starting value
return $args;
}

@ingert
Copy link

ingert commented Feb 1, 2015

Did you ever figure out how to solve your problem emilysnothere? I have the exact same issue.
Basically, I want to set a suggested product quantity (not a minimum quantity) in the shop, and leave it up to the customer how many items they add into the cart. But the cart quantity keep copying the starting input value from the shop...
Any idea how I fix this?
thanks!

@oblaum
Copy link

oblaum commented Mar 23, 2015

is there a way to have a default quantity field in the admin, so i can enter a default quantity for each product?

@aliqorbani
Copy link

hello there
I have set minimum_quantity as a custom field to each product.
how can i set it to quantity input value?

@umairakram500
Copy link

do this for admin order item qty

// admin set qty input steps
add_filter('woocommerce_quantity_input_step', 'adminApplyArgsStep', 10, 2);

function adminApplyArgsStep($step, $product) {
if(is_admin()) {
$step = 0.01; // Has to be 0.01 to not conflict with step intervals and allow the admin to totally customize the quantity in backend
}
return $step;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment