Home Forums Theme Support Dokan Enable Manage Stock by default

This topic is: resolved

This topic contains 10 replies, has 5 voices, and was last updated by  Jesus 4 years, 11 months ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #21426

    Jesus
    Member
    Post count: 17

    I want the stock to be equal to 1 and I was able to achieve that by replacing line 19 in inventory.php (location:dokan/templates/edit) with this line

    <?php dokan_post_input_box( $post->ID, '_stock', array( 'value' => '1' ) ); ?>

    The problem is that if the “Manage Stock” option is not enabled the stock quantity is ignored and you can still add more than 1 to your cart. When the stock management is enabled, and the quantity is 1, the number box, and the plus and minus sign disappear in the product page. That's how I know that the quantity is working.

    So, how can I enable “Manage Stock” by default?

    Thanks for all your help!

    #21464

    Sk
    Moderator
    Post count: 371

    hello Jesus,

    please navigate to dokan/templates/edit/inventory.php replace line 12 by the following code.

    <?php dokan_post_input_box( $post->ID, '_manage_stock', array('label' => __( 'Enable stock management at product level', 'dokan' ), 'value' => 'yes' ), 'checkbox' ); ?>

    Thank you

    #21475

    Jesus
    Member
    Post count: 17

    I replaced line 12, and now, after submitting a new product, the stock management box is checked and the stock quantity is equal to 1. Unfortunately, I can still select more than 1 when adding the item to the cart.

    There must be something that sets the stock quantity value and the stock management value by default when creating the product.

    The solution above only makes it appear as if there is 1 in stock and stock management option enabled, but the actual values are set differently for the product when it's created.

    Where can we find and edit those default values?

    Thanks!

    #21530

    Jesus
    Member
    Post count: 17

    I was able to resolve this.

    I don't know if this is the correct way of doing it or if there's an easier way, but here's what I did:
    I opened new-product.php (Location: /themes/dokan/templates/new-product.php).

    After this line (line 12 in my file)
    if ( isset( $_POST['add_product'] ) ) {' I added '$manageTheStock = isset( $_POST['_manage_stock'] ) ? 'yes' : 'no'; and $onlyOneInStock = isset( $_POST['_stock'] );

    then after this line (line 61 in my file) update_post_meta( $product_id, '_visibility', 'visible' ); I added this update_post_meta( $product_id, '_manage_stock', $manageTheStock ); and this update_post_meta( $product_id, '_stock', $onlyOneInStock );

    After setting the variables and the update functions I just added hidden fields for both inside the new product form.
    <input type="hidden" name="_manage_stock" class="dokan-feat-image-id" value="yes"> <input type="hidden" name="_stock" class="dokan-feat-image-id" value="1">

    And that's it. Doing this does the trick of setting the stock to 1 and enabling the stock management when you post a new product.

    #21570

    Nizam Uddin
    Keymaster
    Post count: 670

    Hello Jusus
    Great job! Thanks for sharing..

    #21896

    Will
    Member
    Post count: 28

    Question on this. How did you get your child theme inventory.php file to overwrite the parent file? I can't seem to get any of the functions in my child theme to actually overwrite!

    #21926

    Jesus
    Member
    Post count: 17

    Hi Will,
    I don't know if this is the answer you are looking for, but it brought up some issues in my end, and I wasn't aware of it. So thank you!

    Here's your possible solution:
    Once you've done what I did above you know now you have two these two variables: -> _stock and _manage_stock. To see these variables reflected in the inventory.php file and webpage all you need to do is call those variables in the value attribute of their specific input tag.

    So, open inventory.php and let's do first the manage stock checkbox.

    Where it says

    <?php 
    dokan_post_input_box( $post->ID, '_manage_stock', array('label' => __('Enable stock management at product level', 'dokan' ), 'value' => variable will go here ),'checkbox' ); 
    ?>

    (this is around line 12)

    replace it with this:

    <?php 
    $manageStock123 = get_post_meta( $post->ID, '_manage_stock', true );
    dokan_post_input_box( $post->ID, '_manage_stock', array('label' => __('Enable stock management at product level', 'dokan' ), 'value' => $manageStock123 ),'checkbox' ); 
    ?>

    and for the stock quantity look for a line that is similar to this:
    <?php dokan_post_input_box( $post->ID, '_stock', array( 'value' => variable will go here ) ); ?>
    (around line 19)

    replace with this:

    <?php
    $stockQuantity123 = get_post_meta( $post->ID, '_stock', true );
    dokan_post_input_box( $post->ID, '_stock', array( 'value' => $stockQuantity123 ) ); 
    ?>

    This should reflect the stock quantity and the manage stock option in your inventory once you edit a product or create a new one.

    Thanks!

    #21977

    zayra
    Member
    Post count: 6

    Its there a easy way to change it. Also to give the seller the option to put how many of their products has in stock????

    2.Also, why the link for the seller to edit the product doesnt show up?
    3.How to put social buttons to give the visitors share the products.
    4.How to add size options???

    #22020

    Will
    Member
    Post count: 28

    Thanks Jesus. What I realized afterwards was that I wasn't putting the inventory.php file in the right place. I had forgotten to put it in a templates folder so it wasn't overwritting the parent file properly. Thanks for the detailed explanation!

    #22029

    Sk
    Moderator
    Post count: 371

    Thanks Jesus,

    You are awesome.

    #22031

    Jesus
    Member
    Post count: 17

    Hi Zayra,
    it's not easy if this is your first time. But this is what you have to do (Considering you already followed what I did above).

    If you want to add a stock quantity to your new product before posting it just add these input fields to the for in new-product.php (Location: /themes/dokan/templates/new-product.php) inside the form.

    <input type="number" name="_stock" min="1" max="5"> (You can change the min and max)

    And make sure you have manage stock field too.

    <input type="hidden" name="_manage_stock" class="dokan-feat-image-id" value="yes">

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

The topic ‘Enable Manage Stock by default’ is closed to new replies.