Enable Manage Stock by default

This topic contains 10 reply and 5 voices, and was last updated by Jesus 9 years, 10 months ago
Viewing 10 Posts - 1 through 10 (of 10 total)
Author Posts
June 4, 2014 at 9:38 pm 21426
Jesus 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!
June 5, 2014 at 2:38 pm 21464
Sk Sk

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

June 5, 2014 at 8:58 pm 21475
Jesus Jesus

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!

June 6, 2014 at 10:04 pm 21530
Jesus Jesus

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.

June 7, 2014 at 2:57 pm 21570
Nizam Uddin Nizam Uddin

Hello Jusus
Great job! Thanks for sharing..

June 13, 2014 at 10:25 pm 21896
Will Will

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!

June 14, 2014 at 10:41 pm 21926
Jesus Jesus

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!

June 16, 2014 at 5:21 am 21977
zayra zayra

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???

June 16, 2014 at 9:51 pm 22020
Will Will

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!

June 17, 2014 at 1:30 am 22029
Sk Sk

Thanks Jesus,

You are awesome.

June 17, 2014 at 3:08 am 22031
Jesus Jesus

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 10 Posts - 1 through 10 (of 10 total)