php - WooCommerce Quantity in Dropdown menu instead of clasic

admin2025-06-03  3

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

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:

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

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

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

Share Improve this question edited Feb 9, 2019 at 0:59 rudtek 6,4035 gold badges30 silver badges52 bronze badges asked Feb 9, 2019 at 0:24 upss1988upss1988 178 bronze badges 1
  • Hi, maybe increase your steps to 7 and add it as the last in the for loop? – Nathaniel Flick Commented Feb 9, 2019 at 4:59
Add a comment  | 

1 Answer 1

Reset to default 0

Use this below code for displaying text like "Contact us" below number 6... Please have a look this screenshot http://prntscr/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>';
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748925451a314872.html

最新回复(0)