Last active
August 30, 2018 08:37
-
-
Save rupomkhondaker/01a9b3d445694f62cb559d32080a7181 to your computer and use it in GitHub Desktop.
This will change normal qty input field to a qty dropdown working with cart and product page all issue fixed tested up 3.4.+
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
function woocommerce_quantity_input($data = null) { | |
global $product; | |
if (!$data) { | |
$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;margin: 4px;', $product ) | |
); | |
} else { | |
$defaults = array( | |
'input_name' => $data['input_name'], | |
'input_value' => $data['input_value'], | |
'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;margin: 4px;', $product ) | |
); | |
} | |
if ( ! empty( $defaults['min_value'] ) ) | |
$min = $defaults['min_value']; | |
else $min = 1; | |
if ( ! empty( $defaults['max_value'] ) ) | |
$max = $defaults['max_value']; | |
else $max = 100; | |
if ( ! empty( $defaults['step'] ) ) | |
$step = $defaults['step']; | |
else $step = 1; | |
$options = ''; | |
//fix add to cart data to send on cart page | |
if (!empty($defaults['input_name'])) { | |
$name = esc_attr($defaults['input_name']); | |
} else { | |
$name = 'quantity'; | |
} | |
for ( $count = $min; $count <= $max; $count = $count+$step ) { | |
$selected = $count === $defaults['input_value'] ? ' selected' : ''; | |
$options .= '<option value="' . $count . '"'.$selected.'>' . $count . '</option>'; | |
} | |
echo '<div class="quantity_select" style="' . $defaults['style'] . '"><select name="' . $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