Skip to content

Instantly share code, notes, and snippets.

@jameskoster
Last active March 8, 2021 14:03
Show Gist options
  • 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;
}
@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