$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>php - WooCommerce Quantity in Dropdown menu instead of clasic|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - WooCommerce Quantity in Dropdown menu instead of clasic

matteradmin9PV0评论
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>';
}
Post a comment

comment list (0)

  1. No comments so far