On Admin Woocommerce product pages, for variable products, on "Variations" settings, for all product variations, I would like to have Manage Stock option enabled by default with the Stock Quantity option set to 1.
Using Get Woocommerce to Manage Stock as a default answer code, I am able to do it for the default inventory tab (for the parent variable product).
I even tried Woocommerce: Creating variations - Manage stock checked by default answer code, but it didn't worked form me.
Any help will be appreciated.
For info, woocommerce_product_variation_get_manage_stock
hook doesn't exist anymore.
Based on jQuery code, the following will enable Manage Stock and will set Stock Quantity to 1, for all product variations:
add_action( 'admin_footer', 'custom_admin_product_variations_js' );
function custom_admin_product_variations_js() {
global $post_type;
if ( 'product' === $post_type ) :
?><script type='text/javascript'>
jQuery( function($) {
$('#variable_product_options').on( 'change', function(){
$('input.variable_manage_stock').each( function(){
if( ! $(this).is(':checked') ){
$(this).attr('checked', 'checked').closest('div').find('.wc_input_stock').val(1);
}
});
});
});
</script><?php
endif;
}
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments