Set default Product Quantity from 1 to 0
-
How can i change the default Product Quantity from 1 to 0 of all the product simple and variable?
I tried all kind of snippets and plugins but nothing seems to be working…
-
I don’t understand why you’d want to do this. If some one clicks on the add to cart button with a 0 quantity, the item gets added to the cart anyway which is weird experience. Better I think, to not have that be an option. But if you insist there is a
woocommerce_quantity_input_min
filter that you can use:add_filter( 'woocommerce_quantity_input_min', 'so_input_min', 20, 2 ); function so_input_min( $min, $product ){ return 0; }
Hello Helga,
Thanks for your help!Could you please guide me how to implement your filter into my site?
Were do I copy and paste this filter into?The easiest would be to add it to your theme’s
functions.php
file.I paste your code into the functions.php of my theme but nothing changes…
It still 1I’m looking for the same thing, I’m able to set the default value to 0 but the item is still added to cart with a quantity of 1. I’ve tried to fix this issue but had not luck!
Surely there is a fix?
I’m with @helgatheviking on this one, not sure why you would want to do this.
For simple products, this should work:
function so_input_min( $args, $product ){ // set the values to 0 $args['input_value'] = 0; $args['min_value'] = 0; return $args; } add_filter( 'woocommerce_quantity_input_args', 'so_input_min', 20, 2 );
This will not work for variable products, and probably not any additional product types added by plugins. This is due to values are set via JavaScript on variable products when the product variation is selected.
Variations can be modified directly in the
single-product/add-to-cart/variable.php
template, which would need to be copied to your theme. You can add the below on line 16:// go through each variation foreach ( $available_variations as $k => $v ) { // set the min quantity to 0 $available_variations[$k]['min_qty'] = 0; }
Again, not sure why you’d want to do this.
@it. Oops, sorry @jessepierson’s code is more accurate since I only modified the minimum and forgot to also filter the default value.
@lukem15 as I tried to explain, even if the item is 0 on the product page, it will be added to the cart with a quantity of 1, so the cart is not effected the filter. If an item has a quantity of zero in the cart then it is removed from the cart. Can you explain the why you would it to be otherwise? It might be that we can suggest an alternative approach.
Normally, I’m of a mind that everything is possible given enough time/resources, but I just don’t see the point of spending that kind of time to decrease your site’s user experience.
@helgatheviking
It’s useful because:Let’s say you sell paper cards.
A customer puts 75 cards into his cart and places the order, later he remembers that he forgot the envelopes so he has to place a new order for only these envelopes.It would be great to have the envelopes already in the cart by entering the cart page. This happens automatically.
But then the quantity is also already 1. I want this to be 0, because if a customer doesn’t pay attention he orders 1 envelop and he gets angry afterwards. I want this product to be an option.
So standard the quantity is 0 and the customer can deside for him self if he wants to change the quantity.A better solution to the issue you mentioned would be cross sells or bundled products.
I’m sure there’s even a plugin out there that can pop up and ask the user, “Did you forget something?”
Product Bundles sounds like a better solution to me too. You could create create a per-item pricing bundle and have the envelopes be “optional”. That way someone could click on the envelopes to have them added at the same time as adding the cards.
Or perhaps Force Sells might work (in that envelopes could be auto-added if cards are added), but I’m a little more familiar with Bundles.
I just don’t think you are going to be able to easily get around the fact that WooCommerce removes 0 quantity items from the cart.
Tahnks @jesse Pearson for this solutions.
But i have one problem.
If a customer adds to the cart product with zero quantity, then in cart i see normal price for 1 pcs. Not zero price.The ideal would be, If a customer adds a product with zero quantity, then in cart will also price set to zero. It is possible please?
Sorry for my google english ??
You cannot add ‘0’ to the cart.
Hmm, then how can I solve my problem?
I have a shop to sell filaments for 3D printers.
In administration I have defined price for the whole package of filaments. For example 40,- EUR.
I need to allow customers to buy the whole package or just the length in meters – price for 1 meter is for example 1,- EUR.
For this feature i use a plugin Product Add-ons by whoothemes https://docs.woothemes.com/document/product-add-ons/In this plugin i can add additional paid (or free!) options for my products.
I have a additional field, where the customer sets the required length in meters for a price 1,- EYR, but that price is then added to the original price.If a customer buys only 1 meter so the final price is 40+1.
For that reason i need to set package price to zero…Since you’re using a paid extension, you should submit a support ticket to WooThemes:
https://www.woothemes.com/my-account/create-a-ticket/The ninjas over there will be able to help you out.
Assuming add-ons work at the variation level, you could use set up a variable product so that 1 variation is the package of filaments and the other is the per meter price? Otherwise, I’m pretty certain that the measurement price calculator does work at the variation level and might be more appropriate.
- The topic ‘Set default Product Quantity from 1 to 0’ is closed to new replies.