0

I have this code which gives me the dropdown menu for Quantity in Add to card section in WooCommerce:

function woocommerce_quantity_input() {
global $product;
$defaults = array(
    'input_name'    => 'quantity',
    'input_value'   => '1',
    'max_value'     => apply_filters( 'woocommerce_quantity_input_max', '', $product ),
    'min_value'     => apply_filters( 'woocommerce_quantity_input_min', '', $product ),
    'contact' => apply_filters('woocommerce_quantity_input_max', 'Contact'),
    'step'      => apply_filters( 'woocommerce_quantity_input_step', '1', $product ),
    'style'     => apply_filters( 'woocommerce_quantity_style', 'float:left; margin-right:10px;', $product )
);
if ( ! empty( $defaults['min_value'] ) )
    $min = $defaults['min_value'];
else $min = 1;
if ( ! empty( $defaults['max_value'] ) )
    $max = $defaults['max_value'];
else $max = 6;
if ( ! empty( $defaults['step'] ) )
    $step = $defaults['step'];
else $step = 1;
$options = '';
for ( $count = $min; $count <= $max; $count = $count+$step ) {
    $options .= '<option value="' . $count . '">' . $count . '</option>';
}


echo '<div class="quantity_select" style="' . $defaults['style'] . '"><select name="' . esc_attr( $defaults['input_name'] ) . '" title="' . _x( 'Qty', 'Product quantity input tooltip', 'woocommerce' ) . '" class="qty">' . $options . '</select></div>';
}

This gives something like this, see this screenshot: https://prnt.sc/mima4f

And now I need to put some text like "Contact us" below number 6. Can you someone explain to me how can I do that.

Thanks

1
  • Hi, maybe increase your steps to 7 and add it as the last in the for loop? Commented Feb 9, 2019 at 4:59

1 Answer 1

0

Use this below code for displaying text like "Contact us" below number 6... Please have a look this screenshot http://prntscr.com/mio5ts

function woocommerce_quantity_input() {
global $product;
$defaults = array(
    'input_name'    => 'quantity',
    'input_value'   => '1',
    'max_value'     => apply_filters( 'woocommerce_quantity_input_max', '', $product ),
    'min_value'     => apply_filters( 'woocommerce_quantity_input_min', '', $product ),
    'contact' => apply_filters('woocommerce_quantity_input_max', 'Contact'),
    'step'      => apply_filters( 'woocommerce_quantity_input_step', '1', $product ),
    'style'     => apply_filters( 'woocommerce_quantity_style', 'float:left; margin-right:10px;', $product )
);
if ( ! empty( $defaults['min_value'] ) )
    $min = $defaults['min_value'];
else $min = 1;
if ( ! empty( $defaults['max_value'] ) )
    $max = $defaults['max_value'];
else $max = 6;
if ( ! empty( $defaults['step'] ) )
    $step = $defaults['step'];
else $step = 1;
$options = '';
for ( $count = $min; $count <= $max + 1; $count = $count+$step ) {
    if($count <= $max){
        $options .= '<option value="' . $count . '">' . $count . '</option>';
    }else{
        $options .= '<option value="contact-us">Contact us</option>';
    }
}
echo '<div class="quantity_select" style="' . $defaults['style'] . '"><select name="' . esc_attr( $defaults['input_name'] ) . '" title="' . _x( 'Qty', 'Product quantity input tooltip', 'woocommerce' ) . '" class="qty">' . $options . '</select></div>';
}
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.