autoship_scheduled_order_quantity_input (function)
( src/scheduled-orders.php) Mimics the WooCommerce 'woocommerce_quantity_input' filter and is used to output the quantity input for Customer Native UI Scheduled Orders display. It takes (WC quantity input) $args (array), (Autoship Cloud) $product (obj), $wc_product, and $echo (bool) as its parameters and will either echo or return the quantity display.
Function
/** * Output the quantity input for Autoship Scheduled Order Edit form. * Mimics the WC {@see woocommerce_quantity_input} function but deals with autoship specific. * * @param array $args Args for the input. * @param stdClass $product Autoship Product Object. * @param WC_Product|null $wc_product Product. * @param boolean $echo Whether to return or echo|string. * * @return string */ function autoship_scheduled_order_quantity_input( $args, $product, $wc_product, $echo = true ){ if ( null !== $wc_product ){ $defaults = array( 'input_id' => uniqid( 'quantity_' ), 'input_name' => 'quantity', 'input_value' => '1', 'max_value' => apply_filters( 'woocommerce_quantity_input_max', -1, $wc_product ), 'min_value' => apply_filters( 'woocommerce_quantity_input_min', 0, $wc_product ), 'step' => apply_filters( 'woocommerce_quantity_input_step', 1, $wc_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 ), $wc_product ); } else { $defaults = array( 'input_id' => uniqid( 'quantity_' ), 'input_name' => 'quantity', 'input_value' => '1', 'max_value' => apply_filters( 'autopship_scheduled_order_quantity_input_max', -1, $product ), 'min_value' => apply_filters( 'autopship_scheduled_order_quantity_input_min', 0, $product ), 'step' => apply_filters( 'autopship_scheduled_order_quantity_input_step', 1, $product ), 'pattern' => apply_filters( 'autopship_scheduled_order_quantity_input_pattern', '[0-9]*' ), 'inputmode' => apply_filters( 'autopship_scheduled_order_quantity_input_inputmode', 'intval' ), ); $args = apply_filters( 'autoship_scheduled_order_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']; } ob_start(); if ( $args['max_value'] && $args['min_value'] === $args['max_value'] ) { ?> <div class="quantity hidden"> <input type="hidden" id="<?php echo esc_attr( $args['input_id'] ); ?>" class="qty" name="<?php echo esc_attr( $args['input_name'] ); ?>" value="<?php echo esc_attr( $args['min_value'] ); ?>" /> </div> <?php } else { /* translators: %s: Quantity. */ $labelledby = ! empty( $args['product_name'] ) ? sprintf( __( '%s quantity', 'autoship' ), strip_tags( $args['product_name'] ) ) : ''; ?> <div class="quantity"> <label class="screen-reader-text" for="<?php echo esc_attr( $args['input_id'] ); ?>"><?php esc_html_e( 'Quantity', 'autoship' ); ?></label> <input type="number" id="<?php echo esc_attr( $args['input_id'] ); ?>" class="input-text qty text" step="<?php echo esc_attr( $args['step'] ); ?>" min="<?php echo esc_attr( $args['min_value'] ); ?>" max="<?php echo esc_attr( 0 < $args['max_value'] ? $args['max_value'] : '' ); ?>" name="<?php echo esc_attr( $args['input_name'] ); ?>" value="<?php echo esc_attr( $args['input_value'] ); ?>" title="<?php echo esc_attr_x( 'Qty', 'Product quantity input tooltip', 'autoship' ); ?>" size="4" pattern="<?php echo esc_attr( $args['pattern'] ); ?>" inputmode="<?php echo esc_attr( $args['inputmode'] ); ?>" aria-labelledby="<?php echo esc_attr( $labelledby ); ?>" /> </div> <?php } $input_display = apply_filters( 'autoship_scheduled_order_quantity_input_display', ob_get_clean() , $args, $product, $wc_product, $echo ); if ( $echo ) { echo $input_display; } else { return $input_display; } }