Advertisement
alamin_89

Quantity drop down

Jun 19th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. // override the quantity input with a dropdown
  2.  
  3. function woocommerce_quantity_input() {
  4.     global $product;
  5.  
  6.     $defaults = array(
  7.         'input_name'    => 'quantity',
  8.         'input_value'   => '1',
  9.         'max_value'     => apply_filters( 'woocommerce_quantity_input_max', '', $product ),
  10.         'min_value'     => apply_filters( 'woocommerce_quantity_input_min', '', $product ),
  11.         'step'      => apply_filters( 'woocommerce_quantity_input_step', '1', $product ),
  12.         'style'     => apply_filters( 'woocommerce_quantity_style', 'float:left; margin-right:10px;', $product )
  13.     );
  14.     if ( ! empty( $defaults['min_value'] ) )
  15.         $min = $defaults['min_value'];
  16.     else $min = 1;
  17.  
  18.     if ( ! empty( $defaults['max_value'] ) )
  19.         $max = $defaults['max_value'];
  20.     else $max = 20;
  21.  
  22.     if ( ! empty( $defaults['step'] ) )
  23.         $step = $defaults['step'];
  24.     else $step = 1;
  25.  
  26.     $options = '';
  27.     for ( $count = $min; $count <= $max; $count = $count+$step ) {
  28.         $options .= '<option value="' . $count . '">' . $count . '</option>';
  29.     }
  30.     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>';
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement