Advertisement
Guest User

Untitled

a guest
Nov 9th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.64 KB | None | 0 0
  1. /**
  2.  * Output the quantity input for add to cart forms.
  3.  *
  4.  * @param  array $args Args for the input.
  5.  * @param  WC_Product|null $product Product.
  6.  * @param  boolean $echo Whether to return or echo|string.
  7.  *
  8.  * @return string
  9.  */
  10.  
  11. function woocommerce_quantity_input($args = array(), $product = null, $echo = true)
  12. {
  13.     if (is_null($product)) {
  14.         $product = $GLOBALS['product'];
  15.     }
  16.  
  17.     $defaults = array(
  18.       'input_id' => uniqid('quantity_'),
  19.       'input_name' => 'quantity',
  20.       'input_value' => '1',
  21.       'max_value' => apply_filters('woocommerce_quantity_input_max', -1, $product),
  22.       'min_value' => apply_filters('woocommerce_quantity_input_min', 0, $product),
  23.       'step' => apply_filters('woocommerce_quantity_input_step', 1, $product),
  24.       'pattern' => apply_filters('woocommerce_quantity_input_pattern', has_filter('woocommerce_stock_amount', 'intval') ? '[0-9]*' : ''),
  25.       'inputmode' => apply_filters('woocommerce_quantity_input_inputmode', has_filter('woocommerce_stock_amount', 'intval') ? 'numeric' : ''),
  26.     );
  27.  
  28.     $args = apply_filters('woocommerce_quantity_input_args', wp_parse_args($args, $defaults), $product);
  29.  
  30.     // Apply sanity to min/max args - min cannot be lower than 0.
  31.     $args['min_value'] = max($args['min_value'], 0);
  32.     $args['max_value'] = 0 < $args['max_value'] ? $args['max_value'] : '';
  33.  
  34.     // Max cannot be lower than min if defined.
  35.     if ('' !== $args['max_value'] && $args['max_value'] < $args['min_value']) {
  36.         $args['max_value'] = $args['min_value'];
  37.     }
  38.  
  39.     $is_weight_product = get_post_meta($product->get_id(), '_is_weight_product', true);
  40.     $is_sale_all_stock = get_post_meta($product->get_id(), '_is_sale_all_stock', true);
  41.     $lower_to_sale_all = get_post_meta($product->get_id(), '_lower_to_sale_all', true);
  42.  
  43. //
  44. //    if ($is_weight_product == 'yes') {
  45. //        $args['step'] = 50;
  46. //        $args['input_value'] = 50;
  47. //    }
  48. //
  49. //    if ($is_sale_all_stock == 'yes') {
  50. //        $args['input_value'] = $args['max_value'];
  51. //        $args['min_value'] = $args['max_value'];
  52. //
  53. //        add_filter('woocommerce_short_description', 'add_message_to_desc');
  54. //    }
  55.  
  56.  
  57.     /**
  58.      * $lower_to_sale_all 500 int
  59.      * (int)$args['max_value'] 720 int
  60.      */
  61.     if ($lower_to_sale_all  >= (int)$args['max_value']) {
  62.         $args['min_value'] = $args['max_value'];
  63.         add_filter('woocommerce_short_description', 'add_message_to_desc');
  64.     }
  65.  
  66.  
  67.     ob_start();
  68.  
  69.     wc_get_template('global/quantity-input.php', $args);
  70.  
  71.     if ($echo) {
  72.         echo ob_get_clean(); // WPCS: XSS ok.
  73.     } else {
  74.         return ob_get_clean();
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement