Is there a hook that would allow setting the Inventory > Manage Stock checkbox in woocommerce globally?
All my products are single item quantity, so it seems pretty counter-D.R.Y to always have to remember to check it, especially for other employees.
Although this is quite late, since you asked about a hook: although there doesn’t appear to be a hook, action or function specifically for turning on the
Manage Stock
option, you can still hook into the post save function and auto-enable it that way, since it is just a post_meta value:Note that stock levels will always default to 0, so you may also want to add the line:
…which will update your stock quantity to 1. Do be aware that this will happen every time a product is saved, though.
I’m unsure as to whether this has knock-on effects elsewhere in WooCommerce for larger stock quantities, but as you’re dealing with single-quantity items, I’d guess you’re probably okay.
Update (with $update):
As of WordPress 3.7, a third parameter was added to
save_post
so you can easily tell if it’s a new post being created or an existing post being updated. As such, you can fire the function above only when creating a new post (which is arguably the desired effect):(Thanks to Dylan for the reminder about post-type specific saves)
A little late, but here’s how for anyone else needing to do this… I found most of this code somewhere else, but I don’t have the link anymore to where I found it. Tweaked it a little and this is what I ended up with (add to functions.php):
Woocommerce now has it’s own hook for saving a product. For a simple product it’s
woocommerce_process_product_meta_simple
.Before updating the meta, we should first check that the
_manage_stock
is empty i.e. the checkbox has not been checked, so that it only triggers on products which have not already been set.Then toggle the manage stock and set the default stock number.