WooCommerce: Setting a specific stock number for all products but a selected few?

Client wanted to have inventory management, but the items are all produced on-demand – except for unique specimens, which are either custom-made pieces which have been returned, or have been produced as a side or test run.

So, we decided to enable inventory management, and set the stock number for all items in any category BUT the “Einzelstücke” (singular pieces) to 999, and items in that specific category to 1.

There certainly are plugins and a few screencasts / tutorials how to do achieve this, but the crafty developer who’s at least a bit versed with SQL might just prefer the following approach:

  1. Before-hand: _stock is the meta field used for inventory management by WooCommerce.
  2. SQL command:
    UPDATE {prefix}postmeta SET meta_value = '999' WHERE meta_key = 'stock'

    solves the issue with pre-existing products

  3. The following SQL subquery should solve any issues with (public) products which have not yet set a fixed stock value:
    UPDATE {prefix}postmeta SET meta_value = '999' WHERE meta_key = 'stock' AND post_id IN (SELECT ID FROM {prefix}posts WHERE product_type = 'product' AND post_status = 'publish')
  4. Head over into the WP admin area, to the product overview, filter by the specific category, and then select all the products that should have a specific different amount
  5. Select “Edit” from the action menu and click the “Apply” button
  6. This should display an edit form to mass-edit all selected products
  7. Now select “Stock qty”, select “Change to:” and then enter the desired different number (in our case: 1)
  8. Apply the changes with clicking on the “Update” button
  9. et voila! Done 😉

Leave a Reply

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