Home Forums Theme Support Dokan Default Inventory Management

This topic is: resolved

Tagged: ,

This topic contains 1 reply, has 2 voices, and was last updated by  Sk 4 years, 11 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #21835

    Will
    Member
    Post count: 28

    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!

    #21845

    Sk
    Moderator
    Post count: 371

    Hello Will,

    Please checkout this topic. Maybe it could help you.

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

    Thank you.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Default Inventory Management’ is closed to new replies.