woocommerce_quantity_input

Output the quantity input for add to cart forms.

Description

woocommerce_quantity_input( (array) $args = array(), (constant) $product = null, (bool) $echo = true ); 

Parameters (3)

0. $args — Optional. (array) => array()
The args.
1. $product — Optional. (constant) => null
The product.
2. $echo — Optional. (bool) => true
The echo.

Usage

  1. if ( !function_exists( 'woocommerce_quantity_input' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-poor-guys-swiss-knife/wcpgsk-fa.php'; 
  3.  
  4. // The args. 
  5. $args = array(); 
  6.  
  7. // The product. 
  8. $product = null; 
  9.  
  10. // The echo. 
  11. $echo = true; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = woocommerce_quantity_input($args, $product, $echo); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wcpgsk-fa.php  
  1. function woocommerce_quantity_input( $args = array(), $product = null, $echo = true ) { 
  2. if ( is_null( $product ) ) 
  3. $product = $GLOBALS['product']; 
  4. $options = get_option( 'wcpgsk_settings' ); 
  5. $product_id = $product->post->ID;  
  6. $selectqty = get_post_meta($product_id, '_wcpgsk_selectqty', true);  
  7. //var_dump( $args ); 
  8. $ival = apply_filters( 'woocommerce_quantity_input_min', '', $product ); 
  9. if ( !$ival ) : 
  10. $ival = apply_filters( 'woocommerce_quantity_input_step', '1', $product ); 
  11. endif; 
  12. $stepval = apply_filters( 'woocommerce_quantity_input_step', '1', $product ); 
  13. $maxval = apply_filters( 'woocommerce_quantity_input_max', '', $product ); 
  14. $mval = apply_filters( 'woocommerce_quantity_input_min', '', $product ); 
  15. if ( !empty($args) && isset($args['input_name']) && strpos($args['input_name'], 'quantity[') !== false ) : 
  16.  
  17. if ( !$ival || (is_numeric( $ival ) && $ival < 1 ) ) : 
  18. if ( $stepval <= $maxval || !$maxval ) : 
  19. $ival = $stepval; 
  20. else : 
  21. $ival = 1; 
  22. endif; 
  23. endif; 
  24. //$mval = 0; 
  25. elseif ( !$ival || (is_numeric( $ival ) && $ival < 1 ) ) : 
  26. if ( $stepval <= $maxval || !$maxval ) : 
  27. $ival = $stepval; 
  28. else : 
  29. $ival = 1; 
  30. endif; 
  31. //$mval = 0; 
  32. endif; 
  33. $defaults = array( 
  34. 'input_name' => 'quantity',  
  35. 'input_value' => $ival,  
  36. 'max_value' => $maxval,  
  37. 'min_value' => $mval,  
  38. 'step' => $stepval,  
  39. 'style' => apply_filters( 'woocommerce_quantity_style', 'float:left; margin-right:10px;', $product ) 
  40. ); 
  41. if ( !empty($args) && isset($args['input_name']) && !empty($args['input_name']) ) : 
  42. $defaults['input_name'] = $args['input_name']; 
  43. endif; 
  44.  
  45. if ( $maxval ) : 
  46. unset( $args['max_value'] ); 
  47. endif; 
  48. $args = apply_filters( 'woocommerce_quantity_input_args', wp_parse_args( $args, $defaults ), $product ); 
  49.  
  50.  
  51. if ( isset($options['cart']['minmaxstepproduct']) && $options['cart']['minmaxstepproduct'] == 1 && isset($selectqty) && $selectqty == 'yes' ) : 
  52.  
  53. $minqty = get_post_meta($product_id, '_wcpgsk_minqty', true); 
  54. $maxqty = get_post_meta($product_id, '_wcpgsk_maxqty', true); 
  55. $stepqty = get_post_meta($product_id, '_wcpgsk_stepqty', true);  
  56.  
  57. if ( ! empty( $args['min_value'] ) ) 
  58. $min = $args['min_value']; 
  59. else $min = $minqty > 0 ? $minqty : 0; 
  60.  
  61. if ( ! empty( $args['max_value'] ) ) 
  62. $max = $args['max_value']; 
  63. else $max = $maxqty > 0 ? $maxqty : ''; 
  64.  
  65. if ( ! empty( $args['step'] ) ) 
  66. $step = $args['step']; 
  67. else $step = $stepqty > 0 ? $stepqty : 1; 
  68. if ( ( !empty( $min ) && is_numeric( $min) ) && ( !empty( $max ) && is_numeric( $max ) ) ) : 
  69. $options = ''; 
  70. for ( $count = $min; $count <= $max; $count = $count+$step ) { 
  71. $options .= '<option value="' . $count . '" ' . selected($count, $args['input_value'], false) . '>' . $count . '</option>'; 
  72. $retstr = '<div class="quantity_select" style="' . $args['style'] . '"><select name="' . esc_attr( $args['input_name'] ) . '" title="' . _x( 'Qty', 'Product quantity input tooltip', 'woocommerce' ) . '" class="qty">' . $options . '</select></div>'; 
  73. if ( $echo ) : 
  74. echo $retstr; 
  75. else : 
  76. return $retstr; 
  77. endif; 
  78.  
  79.  
  80. else : 
  81. extract( $args, EXTR_OVERWRITE ); 
  82. if ( function_exists( 'wc_get_template' ) ) :  
  83. ob_start(); 
  84. wc_get_template( 'global/quantity-input.php', $args ); 
  85. if ( $echo ) { 
  86. echo ob_get_clean(); 
  87. } else { 
  88. return ob_get_clean(); 
  89. else : 
  90. ?> 
  91. <div class="quantity"><input type="number" step="<?php echo esc_attr( $step ); ?>" <?php if ( is_numeric( $min_value ) ) : ?>min="<?php echo esc_attr( $min_value ); ?>"<?php endif; ?> <?php if ( is_numeric( $max_value ) ) : ?>max="<?php echo esc_attr( $max_value ); ?>"<?php endif; ?> name="<?php echo esc_attr( $input_name ); ?>" value="<?php echo esc_attr( $input_value ); ?>" title="<?php _ex( 'Qty', 'Product quantity input tooltip', 'woocommerce' ) ?>" class="input-text qty text" size="4" /></div> 
  92. <?php 
  93. endif; 
  94. endif; 
  95. else : 
  96. extract( $args, EXTR_OVERWRITE ); 
  97. if ( function_exists( 'wc_get_template' ) ) :  
  98. ob_start(); 
  99. wc_get_template( 'global/quantity-input.php', $args ); 
  100. if ( $echo ) { 
  101. echo ob_get_clean(); 
  102. } else { 
  103. return ob_get_clean(); 
  104. else : 
  105. ?> 
  106. <div class="quantity"><input type="number" step="<?php echo esc_attr( $step ); ?>" <?php if ( is_numeric( $min_value ) ) : ?>min="<?php echo esc_attr( $min_value ); ?>"<?php endif; ?> <?php if ( is_numeric( $max_value ) ) : ?>max="<?php echo esc_attr( $max_value ); ?>"<?php endif; ?> name="<?php echo esc_attr( $input_name ); ?>" value="<?php echo esc_attr( $input_value ); ?>" title="<?php _ex( 'Qty', 'Product quantity input tooltip', 'woocommerce' ) ?>" class="input-text qty text" size="4" /></div> 
  107. <?php 
  108. endif; 
  109. endif;