Default Inventory Management

This topic contains 1 reply and 2 voices, and was last updated by Sk 10 years, 5 months ago
Viewing 1 Posts - 1 through 1 (of 1 total)
Author Posts
June 12, 2014 at 8:07 am 21835
Sk I need to have the inventory management turned on by default and inventory set to "1" when someone uploads a product. Normally on the backend the code below will allow you to do this however it doesn't seem to work with this theme (when uploading products from the front end). Not sure if anyone out there can help me as I'm not a super strong coder! Here's the code to set inventory default to 1 and turn on inventory management (when uploading from the backend)
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
  }
}
Any help is appreciated!
June 12, 2014 at 12:19 pm 21845
Sk Sk

Hello Will,

Please checkout this topic. Maybe it could help you.

http://wedevs.com/support/topic/enable-manage-stock-by-default/

Thank you.

Viewing 1 Posts - 1 through 1 (of 1 total)