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()
Args for the input
1. $product — Optional. (constant) => null
The product.
2. $echo — Optional. (bool) => true
Whether to return or echo|string

Usage

  1. if ( !function_exists( 'woocommerce_quantity_input' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-template-functions.php'; 
  3.  
  4. // Args for the input 
  5. $args = array(); 
  6.  
  7. // The product. 
  8. $product = null; 
  9.  
  10. // Whether to return or echo|string 
  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).

/includes/wc-template-functions.php  
  1. function woocommerce_quantity_input( $args = array(), $product = null, $echo = true ) { 
  2. if ( is_null( $product ) ) { 
  3. $product = $GLOBALS['product']; 
  4.  
  5. $defaults = array( 
  6. 'input_name' => 'quantity',  
  7. 'input_value' => '1',  
  8. 'max_value' => apply_filters( 'woocommerce_quantity_input_max', -1, $product ),  
  9. 'min_value' => apply_filters( 'woocommerce_quantity_input_min', 0, $product ),  
  10. 'step' => apply_filters( 'woocommerce_quantity_input_step', 1, $product ),  
  11. 'pattern' => apply_filters( 'woocommerce_quantity_input_pattern', has_filter( 'woocommerce_stock_amount', 'intval' ) ? '[0-9]*' : '' ),  
  12. 'inputmode' => apply_filters( 'woocommerce_quantity_input_inputmode', has_filter( 'woocommerce_stock_amount', 'intval' ) ? 'numeric' : '' ),  
  13. ); 
  14.  
  15. $args = apply_filters( 'woocommerce_quantity_input_args', wp_parse_args( $args, $defaults ), $product ); 
  16.  
  17. // Apply sanity to min/max args - min cannot be lower than 0. 
  18. $args['min_value'] = max( $args['min_value'], 0 ); 
  19. $args['max_value'] = 0 < $args['max_value'] ? $args['max_value'] : ''; 
  20.  
  21. // Max cannot be lower than min if defined. 
  22. if ( '' !== $args['max_value'] && $args['max_value'] < $args['min_value'] ) { 
  23. $args['max_value'] = $args['min_value']; 
  24.  
  25. ob_start(); 
  26.  
  27. wc_get_template( 'global/quantity-input.php', $args ); 
  28.  
  29. if ( $echo ) { 
  30. echo ob_get_clean(); 
  31. } else { 
  32. return ob_get_clean();