If you want to stop this behavior from WooCommerce, you will need to override global/quantity-input.php
template file via your active theme.
First read "How to override woocommerce templates via your active theme" that explains how to copy a template file from WooCommerce plugin to your theme's folder to make some desired changes.
The related template file to copy is: global/quantity-input.php
Once it has been copied inside your theme inside a "woocommerce" folder on "global" subfolder, open / edit quantity-input.php
file and change the following block of code (from line 21
to 25
):
?>
<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
By the following:
?>
<div class="quantity">
<input type="text" id="<?php echo esc_attr( $input_id ); ?>" class="qty" name="<?php echo esc_attr( $input_name ); ?>" value="<?php echo esc_attr( $min_value ); ?>" readonly="readonly" />
</div>
<?php
Save, you are done.
Now when min_value
will be equal to max_value
, the field will be displayed as read only with the correct value.
Now if you need that only in cart page, you will have to make this change instead:
if ( is_cart() ) {
?>
<div class="quantity">
<input type="text" id="<?php echo esc_attr( $input_id ); ?>" class="qty" name="<?php echo esc_attr( $input_name ); ?>" value="<?php echo esc_attr( $min_value ); ?>" readonly="readonly" />
</div>
<?php
} else {
?>
<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
}