Skip to content

Instantly share code, notes, and snippets.

@spraveenitpro
Last active December 11, 2015 06:37
Show Gist options
  • Save spraveenitpro/d4718c15e5f20f988526 to your computer and use it in GitHub Desktop.
Save spraveenitpro/d4718c15e5f20f988526 to your computer and use it in GitHub Desktop.
Minimum, Maximum and a Step for product dropdown
function woocommerce_quantity_input() {
global $product;
$defaults = array(
'input_name' => 'quantity',
'input_value' => '1',
'max_value' => apply_filters( 'woocommerce_quantity_input_max', '20000', $product ),
'min_value' => apply_filters( 'woocommerce_quantity_input_min', '1000', $product ),
'step' => apply_filters( 'woocommerce_quantity_input_step', '1000', $product ),
'style' => apply_filters( 'woocommerce_quantity_style', 'float:left; margin-right:10px;', $product )
);
if ( ! empty( $defaults['min_value'] ) )
$min = $defaults['min_value'];
else $min = 1;
if ( ! empty( $defaults['max_value'] ) )
$max = $defaults['max_value'];
else $max = 20;
if ( ! empty( $defaults['step'] ) )
$step = $defaults['step'];
else $step = 1;
$options = '';
for ( $count = $min; $count <= $max; $count = $count+$step ) {
$options .= '<option value="' . $count . '">' . $count . '</option>';
}
echo '<div class="quantity_select" style="' . $defaults['style'] . '"><select name="' . esc_attr( $defaults['input_name'] ) . '" title="' . _x( 'Qty', 'Product quantity input tooltip', 'woocommerce' ) . '" class="qty">' . $options . '</select></div>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment