Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1130349
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 questionI have hooked the Quantity Selector to change the design and it works fine. But the problem is I can't set the max value dynamically. If I have only 2 items in the stock I need to set max-value as 2. Currently It's not working like that.
Following is the hook that I am using,
function woocommerce_quantity_input($data = null) {
global $product;
if (!$data) {
$defaults = array(
'input_name' => 'quantity',
'input_value' => '1',
'max_value' => apply_filters( 'cw_woocommerce_quantity_input_max', '', $product ),
'min_value' => apply_filters( 'woocommerce_quantity_input_min', '', $product ),
'step' => apply_filters( 'woocommerce_quantity_input_step', '1', $product ),
'style' => apply_filters( 'woocommerce_quantity_style', 'float:left;', $product )
);
}else {
$defaults = array(
'input_name' => $data['input_name'],
'input_value' => $data['input_value'],
'step' => apply_filters( 'cw_woocommerce_quantity_input_step', '1', $product ),
'max_value' => apply_filters( 'cw_woocommerce_quantity_input_max', '', $product ),
'min_value' => apply_filters( 'cw_woocommerce_quantity_input_min', '', $product ),
'style' => apply_filters( 'cw_woocommerce_quantity_style', 'float:left;', $product )
);
}
if ( ! empty( $defaults['min_value'] ) )
$min = $defaults['min_value'];
else
$min = 1;
if ( ! empty( $defaults['max_value'] ) )
$max = $defaults['max_value'];
else
$max = 15;
if ( ! empty( $defaults['input_value'] ) )
$defval = $defaults['input_value'];
else
$defval = 1;
if ( ! empty( $defaults['step'] ) )
$step = $defaults['step'];
else
$step = 1
?>
<div class="woo-single-selection">
<p>Quantity <?php //echo $product->get_stock_quantity(); ?></p>
<div>
<span class="woo-qty-num woo-quantity-input-number-decrement">-</span>
<input class="woo-quantity-input-number input-text qty text cw_qty" type="number" step="<?php echo $step ?>" value="<?php echo $defval ?>" min="<?php echo $min ?>" max="<?php echo $max ?>" name="<?php echo esc_attr( $defaults['input_name'] ) ?>" title="<?php echo _x( 'Qty', 'Product Description', 'woocommerce' ) ?>" pattern="[0-9]*" inputmode="numeric"><span class="woo-qty-num woo-quantity-input-number-increment">+</span>
</div>
</div>
<?php
}
How can set the maximum value as the available stock quantity value?
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 questionI have hooked the Quantity Selector to change the design and it works fine. But the problem is I can't set the max value dynamically. If I have only 2 items in the stock I need to set max-value as 2. Currently It's not working like that.
Following is the hook that I am using,
function woocommerce_quantity_input($data = null) {
global $product;
if (!$data) {
$defaults = array(
'input_name' => 'quantity',
'input_value' => '1',
'max_value' => apply_filters( 'cw_woocommerce_quantity_input_max', '', $product ),
'min_value' => apply_filters( 'woocommerce_quantity_input_min', '', $product ),
'step' => apply_filters( 'woocommerce_quantity_input_step', '1', $product ),
'style' => apply_filters( 'woocommerce_quantity_style', 'float:left;', $product )
);
}else {
$defaults = array(
'input_name' => $data['input_name'],
'input_value' => $data['input_value'],
'step' => apply_filters( 'cw_woocommerce_quantity_input_step', '1', $product ),
'max_value' => apply_filters( 'cw_woocommerce_quantity_input_max', '', $product ),
'min_value' => apply_filters( 'cw_woocommerce_quantity_input_min', '', $product ),
'style' => apply_filters( 'cw_woocommerce_quantity_style', 'float:left;', $product )
);
}
if ( ! empty( $defaults['min_value'] ) )
$min = $defaults['min_value'];
else
$min = 1;
if ( ! empty( $defaults['max_value'] ) )
$max = $defaults['max_value'];
else
$max = 15;
if ( ! empty( $defaults['input_value'] ) )
$defval = $defaults['input_value'];
else
$defval = 1;
if ( ! empty( $defaults['step'] ) )
$step = $defaults['step'];
else
$step = 1
?>
<div class="woo-single-selection">
<p>Quantity <?php //echo $product->get_stock_quantity(); ?></p>
<div>
<span class="woo-qty-num woo-quantity-input-number-decrement">-</span>
<input class="woo-quantity-input-number input-text qty text cw_qty" type="number" step="<?php echo $step ?>" value="<?php echo $defval ?>" min="<?php echo $min ?>" max="<?php echo $max ?>" name="<?php echo esc_attr( $defaults['input_name'] ) ?>" title="<?php echo _x( 'Qty', 'Product Description', 'woocommerce' ) ?>" pattern="[0-9]*" inputmode="numeric"><span class="woo-qty-num woo-quantity-input-number-increment">+</span>
</div>
</div>
<?php
}
How can set the maximum value as the available stock quantity value?
Share Improve this question asked Dec 24, 2018 at 5:39 RameshRamesh 1451 silver badge9 bronze badges 2 |1 Answer
Reset to default 2function max_quantity_single( $max, $product ) {
$stock = get_post_meta( get_the_ID(), '_stock', true );
$max = $stock;
return $max;
}
add_filter( 'woocommerce_quantity_input_max','max_quantity_single', 10, 2 );
Add this hook in your functions.php or plugin file.
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 questionI have hooked the Quantity Selector to change the design and it works fine. But the problem is I can't set the max value dynamically. If I have only 2 items in the stock I need to set max-value as 2. Currently It's not working like that.
Following is the hook that I am using,
function woocommerce_quantity_input($data = null) {
global $product;
if (!$data) {
$defaults = array(
'input_name' => 'quantity',
'input_value' => '1',
'max_value' => apply_filters( 'cw_woocommerce_quantity_input_max', '', $product ),
'min_value' => apply_filters( 'woocommerce_quantity_input_min', '', $product ),
'step' => apply_filters( 'woocommerce_quantity_input_step', '1', $product ),
'style' => apply_filters( 'woocommerce_quantity_style', 'float:left;', $product )
);
}else {
$defaults = array(
'input_name' => $data['input_name'],
'input_value' => $data['input_value'],
'step' => apply_filters( 'cw_woocommerce_quantity_input_step', '1', $product ),
'max_value' => apply_filters( 'cw_woocommerce_quantity_input_max', '', $product ),
'min_value' => apply_filters( 'cw_woocommerce_quantity_input_min', '', $product ),
'style' => apply_filters( 'cw_woocommerce_quantity_style', 'float:left;', $product )
);
}
if ( ! empty( $defaults['min_value'] ) )
$min = $defaults['min_value'];
else
$min = 1;
if ( ! empty( $defaults['max_value'] ) )
$max = $defaults['max_value'];
else
$max = 15;
if ( ! empty( $defaults['input_value'] ) )
$defval = $defaults['input_value'];
else
$defval = 1;
if ( ! empty( $defaults['step'] ) )
$step = $defaults['step'];
else
$step = 1
?>
<div class="woo-single-selection">
<p>Quantity <?php //echo $product->get_stock_quantity(); ?></p>
<div>
<span class="woo-qty-num woo-quantity-input-number-decrement">-</span>
<input class="woo-quantity-input-number input-text qty text cw_qty" type="number" step="<?php echo $step ?>" value="<?php echo $defval ?>" min="<?php echo $min ?>" max="<?php echo $max ?>" name="<?php echo esc_attr( $defaults['input_name'] ) ?>" title="<?php echo _x( 'Qty', 'Product Description', 'woocommerce' ) ?>" pattern="[0-9]*" inputmode="numeric"><span class="woo-qty-num woo-quantity-input-number-increment">+</span>
</div>
</div>
<?php
}
How can set the maximum value as the available stock quantity value?
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 questionI have hooked the Quantity Selector to change the design and it works fine. But the problem is I can't set the max value dynamically. If I have only 2 items in the stock I need to set max-value as 2. Currently It's not working like that.
Following is the hook that I am using,
function woocommerce_quantity_input($data = null) {
global $product;
if (!$data) {
$defaults = array(
'input_name' => 'quantity',
'input_value' => '1',
'max_value' => apply_filters( 'cw_woocommerce_quantity_input_max', '', $product ),
'min_value' => apply_filters( 'woocommerce_quantity_input_min', '', $product ),
'step' => apply_filters( 'woocommerce_quantity_input_step', '1', $product ),
'style' => apply_filters( 'woocommerce_quantity_style', 'float:left;', $product )
);
}else {
$defaults = array(
'input_name' => $data['input_name'],
'input_value' => $data['input_value'],
'step' => apply_filters( 'cw_woocommerce_quantity_input_step', '1', $product ),
'max_value' => apply_filters( 'cw_woocommerce_quantity_input_max', '', $product ),
'min_value' => apply_filters( 'cw_woocommerce_quantity_input_min', '', $product ),
'style' => apply_filters( 'cw_woocommerce_quantity_style', 'float:left;', $product )
);
}
if ( ! empty( $defaults['min_value'] ) )
$min = $defaults['min_value'];
else
$min = 1;
if ( ! empty( $defaults['max_value'] ) )
$max = $defaults['max_value'];
else
$max = 15;
if ( ! empty( $defaults['input_value'] ) )
$defval = $defaults['input_value'];
else
$defval = 1;
if ( ! empty( $defaults['step'] ) )
$step = $defaults['step'];
else
$step = 1
?>
<div class="woo-single-selection">
<p>Quantity <?php //echo $product->get_stock_quantity(); ?></p>
<div>
<span class="woo-qty-num woo-quantity-input-number-decrement">-</span>
<input class="woo-quantity-input-number input-text qty text cw_qty" type="number" step="<?php echo $step ?>" value="<?php echo $defval ?>" min="<?php echo $min ?>" max="<?php echo $max ?>" name="<?php echo esc_attr( $defaults['input_name'] ) ?>" title="<?php echo _x( 'Qty', 'Product Description', 'woocommerce' ) ?>" pattern="[0-9]*" inputmode="numeric"><span class="woo-qty-num woo-quantity-input-number-increment">+</span>
</div>
</div>
<?php
}
How can set the maximum value as the available stock quantity value?
Share Improve this question asked Dec 24, 2018 at 5:39 RameshRamesh 1451 silver badge9 bronze badges 2-
@vikrantzilpe thank you for your reply sir. I don't want to use plugins here. I just want to set the
maxvalue equal to theavailable stock quantity value– Ramesh Commented Dec 24, 2018 at 6:35 - @vikrantzilpe It makes to add minimum and maximum value to the product. And also I found this line on the article that you shared "The above solution will only work on the WooCommerce product page. Which means, even after placing above code snippet in functions.php file, the customer can update the quantity on Cart page. Also, it will be applied to all the product available on your store." I want to set the stock amount as the maximum value sir – Ramesh Commented Dec 24, 2018 at 7:32
1 Answer
Reset to default 2function max_quantity_single( $max, $product ) {
$stock = get_post_meta( get_the_ID(), '_stock', true );
$max = $stock;
return $max;
}
add_filter( 'woocommerce_quantity_input_max','max_quantity_single', 10, 2 );
Add this hook in your functions.php or plugin file.
本文标签: Add maxvalue to hooked quantity selector in woocommerce
版权声明:本文标题:Add max-value to hooked quantity selector in woocommerce 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749071452a2311640.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


maxvalue equal to theavailable stock quantity value– Ramesh Commented Dec 24, 2018 at 6:35