当前位置: 动力学知识库 > 问答 > 编程问答 >

woocommerce - initial quantity for product variations

问题描述:

I found this code which allows me to set an initial quantity for simple products: http://docs.woothemes.com/document/adjust-the-quantity-input-values/

It leaves me the freedom to reduce the quantity. (eg. initial quantity = 5 and I could reduce to 3)

But for products with variations it is only possible to set a minimum quantity, not an initial quantity. Unfortunately it is not possible to reduce items.

I've tried to find a solution to only set the initial quantity for product variation, but there seems not to be one.

Does anyone have a solution for this?

网友答案:

if you want just to set the initial amount to 5 and users are allowed to reduce or increase as per their requirement then you just need to set the input value to your desired one.

add_filter( 'woocommerce_quantity_input_args', 'jk_woocommerce_quantity_input_args', 10, 2 );
function jk_woocommerce_quantity_input_args( $args, $product ) {
    $args['input_value']    = 5;    // your desired value
    return $args;
}

Update

By default you are not allowed to do so. But if you insist then you can make a work around. But beware, this might hurt.

If your theme has the copy of woocommerce template files (generally in a folder named woocommerce in the root of your template directory). Navigate to [your-theme-directory]/woocommerce/global/quantity-input.php file and search for qty class in the number input field. Then remove it.

Again I would like to warn you some functionality depends on this class, you can see that in add-to-cart-variations.js file in the plugins assets/js folder. You need to be prepared for that.

分享给朋友:
您可能感兴趣的文章:
随机阅读: