Make Woocommerce Products Sold Individually By Default

So one of my new personal websites sells virtual products where customers buy just one product at a time. I don’t need quantities and nor do I want quantity boxes on the product page or the checkout, there just no need for it. So there could be a way to bring in some jQuery into the WordPress admin to force the check box on the product edit page but a neater solution is to actually just drop this into the functions.php file or seperate plugin file to achieve the same thing:

function default_no_quantities( $individually, $product ){
$individually = true;
return $individually;
add_filter( 'woocommerce_is_sold_individually', 'default_no_quantities', 10, 2 );

Now, when you create a new product, you will notice the checkbox is NOT checked, however if you publish the product with it unchecked, there will be no quantity allocated to the product.

Useful post? Share it

15 comments on “Make Woocommerce Products Sold Individually By Default

  1. Exactly what I needed! (but for the opposite reason). For some reason products were defaulting to sold individually = true even when set to false in the admin. This fixed it!

    1. Hi, this snippet doesn’t remove duplicate products, it enables products to be sold once only per customer. So they can only have one of that product at any time. Hope that helps.

  2. Just a note for other devs – if the behavior you want is to set the default to sold_individually, but still allow the user to choose to sell in quantity and manage stock, then you really probably want to use JQuery rather than this function. for example –
    if(chbk_admin_scripts_vars.hook_suffix == ‘post-new.php’
    && chbk_admin_scripts_vars.post_type == ‘product’
    && $(‘#product-type’).val() == ‘my_custom_product_type’){
    $(‘#_sold_individually’).attr(‘checked’, ‘checked’);

    This way, when the user creates a new product of your custom product type, the sold_individually is checked by default. However, if the user goes in and manually unchecks the sold_individually, the behavior reverts to the default way woocommerce normally handles all new products.

    1. Thanks Meg! That sounds like what I need. Where would you add this jQuery code for this solution to work?

Leave a Reply

Your email address will not be published. Required fields are marked *