-
-
Save splozm/a73d19659dd11e26fcae67d74ae0ba4c to your computer and use it in GitHub Desktop.
WooCommerce Dropdown Product Quantity, including selected quantity in cart. Fully compatible with Min/Max quantities extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Place the following code in your theme's functions.php file | |
// override the quantity input with a dropdown | |
function woocommerce_quantity_input($data = null) { | |
global $product; | |
$defaults = array( | |
'input_name' => 'quantity', | |
'input_value' => '1', | |
'max_value' => apply_filters( 'woocommerce_quantity_input_max', '', $product ), | |
'min_value' => apply_filters( 'woocommerce_quantity_input_min', '', $product ), | |
'step' => apply_filters( 'woocommerce_quantity_input_step', '1', $product ), | |
'style' => apply_filters( 'woocommerce_quantity_style', 'float:left;', $product ) | |
); | |
$data = wp_parse_args( $data, $defaults ); | |
if ( ! empty( $data['min_value'] ) ) | |
$min = $data['min_value']; | |
else $min = 1; | |
if ( ! empty( $data['max_value'] ) ) | |
$max = $data['max_value']; | |
else $max = 20; | |
if ( ! empty( $data['step'] ) ) | |
$step = $data['step']; | |
else $step = 1; | |
$options = ''; | |
for ( $count = $min; $count <= $max; $count = $count+$step ) { | |
$selected = $count === $data['input_value'] ? ' selected' : ''; | |
$options .= '<option value="' . $count . '"'.$selected.'>' . $count . '</option>'; | |
} | |
echo '<div class="quantity_select" style="' . $data['style'] . '"><select name="' . esc_attr( $data['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