Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Output the quantity input for add to cart forms.
- *
- * @param array $args Args for the input.
- * @param WC_Product|null $product Product.
- * @param boolean $echo Whether to return or echo|string.
- *
- * @return string
- */
- function woocommerce_quantity_input($args = array(), $product = null, $echo = true)
- {
- if (is_null($product)) {
- $product = $GLOBALS['product'];
- }
- $defaults = array(
- 'input_id' => uniqid('quantity_'),
- 'input_name' => 'quantity',
- 'input_value' => '1',
- 'max_value' => apply_filters('woocommerce_quantity_input_max', -1, $product),
- 'min_value' => apply_filters('woocommerce_quantity_input_min', 0, $product),
- 'step' => apply_filters('woocommerce_quantity_input_step', 1, $product),
- 'pattern' => apply_filters('woocommerce_quantity_input_pattern', has_filter('woocommerce_stock_amount', 'intval') ? '[0-9]*' : ''),
- 'inputmode' => apply_filters('woocommerce_quantity_input_inputmode', has_filter('woocommerce_stock_amount', 'intval') ? 'numeric' : ''),
- );
- $args = apply_filters('woocommerce_quantity_input_args', wp_parse_args($args, $defaults), $product);
- // Apply sanity to min/max args - min cannot be lower than 0.
- $args['min_value'] = max($args['min_value'], 0);
- $args['max_value'] = 0 < $args['max_value'] ? $args['max_value'] : '';
- // Max cannot be lower than min if defined.
- if ('' !== $args['max_value'] && $args['max_value'] < $args['min_value']) {
- $args['max_value'] = $args['min_value'];
- }
- $is_weight_product = get_post_meta($product->get_id(), '_is_weight_product', true);
- $is_sale_all_stock = get_post_meta($product->get_id(), '_is_sale_all_stock', true);
- $lower_to_sale_all = get_post_meta($product->get_id(), '_lower_to_sale_all', true);
- //
- // if ($is_weight_product == 'yes') {
- // $args['step'] = 50;
- // $args['input_value'] = 50;
- // }
- //
- // if ($is_sale_all_stock == 'yes') {
- // $args['input_value'] = $args['max_value'];
- // $args['min_value'] = $args['max_value'];
- //
- // add_filter('woocommerce_short_description', 'add_message_to_desc');
- // }
- /**
- * $lower_to_sale_all 500 int
- * (int)$args['max_value'] 720 int
- */
- if ($lower_to_sale_all >= (int)$args['max_value']) {
- $args['min_value'] = $args['max_value'];
- add_filter('woocommerce_short_description', 'add_message_to_desc');
- }
- ob_start();
- wc_get_template('global/quantity-input.php', $args);
- if ($echo) {
- echo ob_get_clean(); // WPCS: XSS ok.
- } else {
- return ob_get_clean();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement