Created
July 5, 2022 15:50
-
-
Save jmarreros/9a2f1418af70cbdb7b4176151f61f06d to your computer and use it in GitHub Desktop.
Change Add to Cart Quantity into a Select Drop-down, overrides template: woocommerce/global/quantity-input.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @see https://docs.woocommerce.com/document/template-structure/ | |
* @package WooCommerce\Templates | |
* @version 4.0.0 | |
*/ | |
defined( 'ABSPATH' ) || exit; | |
if ( $max_value && $min_value === $max_value ) { | |
?> | |
<div class="quantity hidden"> | |
<input type="hidden" id="<?php echo esc_attr( $input_id ); ?>" class="qty" name="<?php echo esc_attr( $input_name ); ?>" value="<?php echo esc_attr( $min_value ); ?>" /> | |
</div> | |
<?php | |
} else { | |
/* translators: %s: Quantity. */ | |
$label = ! empty( $args['product_name'] ) ? sprintf( esc_html__( '%s quantity', 'woocommerce' ), wp_strip_all_tags( $args['product_name'] ) ) : esc_html__( 'Quantity', 'woocommerce' ); | |
?> | |
<div class="quantity"> | |
<?php do_action( 'woocommerce_before_quantity_input_field' ); ?> | |
<label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php echo esc_attr( $label ); ?></label> | |
<?php | |
$options = ''; | |
if ( empty($max_value) ) $max_value = 10; | |
for ( $count = $min_value; $count <= $max_value; $count = $count + $step ) { | |
$selected = ($count == $input_value ) ? 'selected' : ''; | |
$options .= '<option value="' . $count . '" ' . $selected . '>' . $count . '</option>'; | |
} | |
$select = '<select name="' . $input_name . '" class="qty" >' . $options . '</select>'; | |
echo $select; | |
?> | |
<?php do_action( 'woocommerce_after_quantity_input_field' ); ?> | |
</div> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment