Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在下拉菜单中输入数量,而不是clasic_Php_Wordpress_Woocommerce - Fatal编程技术网

Php 在下拉菜单中输入数量,而不是clasic

Php 在下拉菜单中输入数量,而不是clasic,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我有一个代码,它为我提供了WooCommerce中“添加到卡”部分的数量下拉菜单: function woocommerce_quantity_input() { global $product; $defaults = array( 'input_name' => 'quantity', 'input_value' => '1', 'max_value' => apply_filters( 'woocommerce_quantity_

我有一个代码,它为我提供了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>';
}
函数\u数量\u输入(){
全球$产品;
$defaults=数组(
'输入名称'=>'数量',
“输入值”=>“1”,
“最大值”=>apply_过滤器('woocommerce_quantity_input_max',''$product),
“最小值”=>apply_过滤器('woocommerce_quantity_input_min',''$product),
'contact'=>应用过滤器('woocommerce\u quantity\u input\u max','contact'),
“步骤”=>apply_filters('woocommerce_quantity_input_step','1',$product),
'style'=>apply_过滤器('woocommerce_quantity_style','float:left;margin-right:10px;',$product)
);
如果(!empty($defaults['min_value']))
$min=$defaults['min_value'];
否则$min=1;
如果(!empty($defaults['max_value']))
$max=$defaults['max_value'];
否则$max=6;
如果(!empty($defaults['step']))
$step=$defaults['step'];
else$step=1;
$options='';

对于($count=$min;$count,请在functions.php中使用以下代码:

function woocommerce_quantity_input( $args = array(), $product = null, $echo = true )         
{
if ( is_null( $product ) ) {
$product = $GLOBALS['product'];
}
$defaults = array(
'input_id'    => uniqid( 'quantity_' ),
'input_name'  => 'quantity',
'input_value' => '1',
'max_value'   => apply_filters( 'woocommerce_quantity_input_max', -1, $product ),
'min_value'   => apply_filters( 'woocommerce_quantity_input_min', 0, $product ),
'step'        => apply_filters( 'woocommerce_quantity_input_step', 1, $product ),
'pattern'     => apply_filters( 'woocommerce_quantity_input_pattern', has_filter( 
'woocommerce_stock_amount', 'intval' ) ? '[0-9]*' : '' ),
'inputmode'   => apply_filters( 'woocommerce_quantity_input_inputmode', has_filter( 
'woocommerce_stock_amount', 'intval' ) ? 'numeric' : '' ),
);

$args = apply_filters( 'woocommerce_quantity_input_args', wp_parse_args( $args, 
$defaults ), $product );

// Apply sanity to min/max args - min cannot be lower than 0.
$args['min_value'] = max( $args['min_value'], 0 );
$args['max_value'] = 0 < $args['max_value'] ? $args['max_value'] : '';

// Max cannot be lower than min if defined.
if ( '' !== $args['max_value'] && $args['max_value'] < $args['min_value'] ) {
$args['max_value'] = $args['min_value'];
}

$options = '';

 for ( $count = $args['min_value']; $count <= $args['max_value']; $count = $count + 
 $args['step'] ) {

// Cart item quantity defined?
if ( '' !== $args['input_value'] && $args['input_value'] > 1 && $count == 
$args['input_value'] ) {
    $selected = 'selected';     
} else $selected = '';

$options .= '<option value="' . $count . '"' . $selected . '>' . $count . 
'</option>';

}

$string = '<div class="quantity"><span>Qty</span><select name="' . 
$args['input_name'] . '">' . $options . '</select></div>';

if ( $echo ) {
echo $string;
} else {
return $string;
}

}
function\u quantity\u输入($args=array(),$product=null,$echo=true)
{
如果(为空($product)){
$product=$GLOBALS['product'];
}
$defaults=数组(
'input_id'=>uniqid('QUOTE_'),
'输入名称'=>'数量',
“输入值”=>“1”,
“最大值”=>apply_过滤器('woocommerce_quantity_input_max',-1,$product),
“最小值”=>apply_过滤器('woocommerce_quantity_input_min',0,$product),
“步骤”=>应用过滤器('woocommerce\u quantity\u input\u step',1$product),
“模式”=>apply_filters('woocommerce_quantity_input_pattern')具有_filter(
“商业库存金额”、“国际价值”)?“[0-9]*”:”,
“inputmode”=>apply_filters(“woocommerce_quantity_input_inputmode”具有_filter(
“商业库存金额”、“intval”)?“数字”:”,
);
$args=apply_filters('woocommerce_quantity_input_args',wp_parse_args($args,
$defaults),$product);
//将健全性应用于最小/最大参数-最小值不能低于0。
$args['min_value']=max($args['min_value'],0);
$args['max_value']=0<$args['max_value']?$args['max_value']:'';
//如果已定义,则最大值不能低于最小值。
如果(“”!=$args['max\u value']&&$args['max\u value']<$args['min\u value']){
$args['max_value']=$args['min_value'];
}
$options='';
对于($count=$args['min_value'];$count 1&&$count==
$args['input_value']){
$selected='selected';
}else$selected='';
$options.=''。$count。
'';
}
$string='Qty'.$options';
如果($echo){
echo$字符串;
}否则{
返回$string;
}
}

我找到了这样的解决方案。对我来说很有效

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>';
}
函数\u数量\u输入(){
全球$产品;
$defaults=数组(
'输入名称'=>'数量',
“输入值”=>“1”,
“最大值”=>apply_过滤器('woocommerce_quantity_input_max',''$product),
“最小值”=>apply_过滤器('woocommerce_quantity_input_min',''$product),
'contact'=>应用过滤器('woocommerce\u quantity\u input\u max','contact'),
“步骤”=>apply_filters('woocommerce_quantity_input_step','1',$product),
'style'=>apply_过滤器('woocommerce_quantity_style','float:left;margin-right:10px;',$product)
);
如果(!empty($defaults['min_value']))
$min=$defaults['min_value'];
否则$min=1;
如果(!empty($defaults['max_value']))
$max=$defaults['max_value'];
否则$max=6;
如果(!empty($defaults['step']))
$step=$defaults['step'];
else$step=1;
$options='';

对于($count=$min;$count),谢谢您。我在下面找到了一个解决方案。