我有这个代码,它为我提供了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>\';
}
这给出了类似的内容,请参见此屏幕截图:
https://prnt.sc/mima4f 现在我需要在数字6下面写一些文字,如“联系我们”。你能给我解释一下我该怎么做吗。
谢谢
最合适的回答,由SO网友:Tanmay Patel 整理而成
使用以下代码在数字6下方显示“联系我们”等文本。。。请看一下这个屏幕截图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>\';
}