Admin Products page – Stock quantity
-
Hi,
If I have 300 main product, 10 variation A, 20 variation B, it will show “In Stock 330” in admin product page.
How to show only parent product’s stock quantity (300) in admin product page?
(without taking off variation stock management)What’s the hook to manage this? (I tried to find it…)
Regards,
Marko
-
The page won’t allow this; 330 is the correct total here if you’re managing stock at both variation and product level). Have you done it like this for a reason?
Thanks for fast reply! š
Yes, 330 is correct total (main product + variations stock) but I made a plugin (which we talked two weeks ago) adds option for product’s variation to reduce main product’s stock amount by certain value.
Also I manage variation’s stock amount by given them values based on this value. (Example. main product 300, variation A value 10, so variation A stock is 30) so everything works beautifully in product’s page in the shop. Taking variation’s stock management off would cause other problems…
Because of this, I would need to have just main product’s stock showing on the products page.
Adding to the customisation you made for this originally, I wonder if you could add a new field to the variation for the reducer qty rather than using stock qty. Then the ‘300’ won’t be affected in any way?
Otherwise this can be adjusted https://github.com/woothemes/woocommerce/blob/master/includes/abstracts/abstract-wc-product.php#L713
Yes I could add new field for the variation as “variation stock”, and take variation stock management off, so it doesn’t affect admin products page’s stock quantity, but I am assuming it will cause more problems when adding products to cart and in checkout page etc…?
Adding products to cart, alerts about trying to add more than there is stock, stock qty management after checkout etc. are working nicely with having variation’s stock management turned on.
offtopic :
(Expect that I need to find the best way to dynamically check/adjust stock so user can’t add more variations to cart than there are main product’s stock. User could buy 30x variation A (10) and 1x variation B (20), total of 320, when main product’s stock is 300)I’ll check can I achieve this with that woocommerce_get_availability filter, it is used by class-wc-product-variation.php and abstract-wc-product.php
> I’ll check can I achieve this with that woocommerce_get_availability filter, it is used by class-wc-product-variation.php and abstract-wc-product.php
You should be able to; you can detect the product type within your function.
Yeah that I was thinking about that. But adding filter to that would affect globally variation/product availability stock quantity, not just admin products page…?
There is no way to narrow my custom filter/function just to work in one page’s call?
Hope you understand what I mean š
Well you can also wrap your function code in is_admin() but I think you’d want to affect all displayed stock qty in this case.
Well, customer only sees variations and their stock quantity – they’ll never see main product’s quantity. Only place where user sees “wrong” stock quantity now is admin products page so basically admin is just the problem.
Wrapping it around is_admin() is very simply way, no idea why I didn’t thing of that. Let see what I do (prolly crash the server few times…) š
Is it possible that admin products page gets that information from some different way than using woocommerce_get_availability filter?
I tested it and it works in shop’s product page but not in admin page? The returning array has key availability => “QTY in stock” and in product page it is in form of “In stock x QTY”
Ah yes. It’s not filterable right now. Someone added a filter in 2.6 named woocommerce_admin_stock_html and looks to be solving the same problem as you.
Yeah, I think admin products page gets the stock from simple product’s stock request or something.
woocommerce_get_stock_quantity -filter is used in the admin page stock display. I can filter through my function to echo out the product’s quantity (the data is only int) and it will echo main product’s stock but it will still show the total stock quantity of main product and variation’s, because the way it’s coded.
Weird, I thought it would echo the total amount, not just main product…‘
add_filter(‘woocommerce_get_stock_quantity’, ‘testings’,10,1);
function testings($product){
if(is_admin()){
echo “<b><font color=’#7ad03a’>Main product in stock : </font></b>”; echo $product; echo “
<hr>”;
}
return $product;
}
‘It does. Thats why the filter has been added in 2.6 to control the HTML.
Ok, thank you very much!
I’ll download 2.6 for my test server and test it out.
Works nicely. Hope it gets added to WooCommerce š
(or some variation of this)add_filter('woocommerce_admin_stock_html', 'admin_product',10,2); function admin_product($stock_html,$product) { if( $product->is_type( 'variable' ) ) { $stock_html = $product->get_stock_quantity() . '<br>' . '<mark class="instock">'. __('In stock', 'woocommerce' ) . '</mark>'; } return $stock_html; }Hi,
I have an issue. I need to maintain product inventory Stock amount to be in decimal like 0.6 and show it as InStock. Currently when a product is below 1, it is showing OutofStock (default in woocommerce)
How this can be get through hooks or filter code?Thanks in advance.
The topic ‘Admin Products page – Stock quantity’ is closed to new replies.