Get Woocommerce to Manage Stock as a default
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:
add_action('save_post', 'myWoo_savePost', 10, 2);
function myWoo_savePost($postID, $post) {
if (isset($post->post_type) && $post->post_type == 'product') {
update_post_meta($post->ID, '_manage_stock', 'yes');
}
}
Note that stock levels will always default to 0, so you may also want to add the line:
update_post_meta($post->ID, '_stock', '1');
...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):
add_action('save_post_product', 'myWoo_savePost', 10, 3);
function myWoo_savePost($postID, $post, $update) {
if (!$update) {
// $update is false if we're creating a new post
update_post_meta($post->ID, '_manage_stock', 'yes');
update_post_meta($post->ID, '_stock', '1');
}
}
(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):
add_action( 'admin_enqueue_scripts', 'wc_default_variation_stock_quantity' );
function wc_default_variation_stock_quantity() {
global $pagenow, $woocommerce;
$default_stock_quantity = 1;
$screen = get_current_screen();
if ( ( $pagenow == 'post-new.php' || $pagenow == 'post.php' || $pagenow == 'edit.php' ) && $screen->post_type == 'product' ) {
?>
<!-- uncomment this if jquery if it hasn't been included
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
-->
<script type="text/javascript">
jQuery(document).ready(function(){
if ( !jQuery( '#_manage_stock' ).attr('checked') ) {
jQuery( '#_manage_stock' ).attr('checked', 'checked');
}
if ( '' === jQuery( '#_stock' ).val() ) {
jQuery( '#_stock' ).val(<?php echo $default_stock_quantity; ?>);
}
});
</script>
<?php
}
}