Display stock availabilty on shop page, WooCommerce
-
How do I make my stock quantity (example: 9 items left) display on my shop page? (under price, next to price, above price, does not matter).
thank you,
SKReimund
-
The product photo does not appear on the site. why?
Can someone help me? I’ve inserted media and deleted it and tried it again and it just won’t show up. HELP!
https://66.147.244.90/~fermentf/product/dill-pickle-kruat/?preview=true&preview_id=527&preview_nonce=a8ed5ddd0e@skreimund
To some extent it depends on whether your theme chooses to show the stock quantity on the Shop page. What theme are you using? Can you post the url to your site?First make sure you have enabled stock control:
Admin page > WooCommerce > Settings > Products > Inventory, “Enable Stock Management” = checked
and (for single products) …
on the relevant product pages, Product Data section, Inventory tab, Enable stock management at product level = checked, and a stock quantity entered
or (for variable products) …
choose between manage stock at product level or manage stock at variation level and set stock quantities.@ferment4health
Please start a new thread for a new problem, as per forum guidelines.
Please complete the form at the bottom of this page:
https://www.ads-software.com/support/plugin/woocommerceStock Management is Enabled, and I am using the mystile theme. What I want is, under the product price (X.XX per Number – that’s what it says, I will link the website), to have the stock quantity left. (for example, “Only XX amount left!”).
I wondered if it is possible.
Try this snippet in functions.php for your child theme:
<?php add_action( 'woocommerce_after_shop_loop_item_title', 'my_stock', 15); function my_stock() { global $product; echo "Stock: ".$product->stock; }
Mate, I am in love with you right now. I would squeeze you into my arms and make sweet love to your coding. The only change I had to make, however, considering I had a variable product and not a simple one, was this:
add_action( ‘woocommerce_after_shop_loop_item_title’, ‘my_stock’, 15);
function my_stock() {
global $product;
echo “Numbers left:”.$product->total_stock;
}instead of stock, i used total_stock
THANK YOU! From the bottom of my heart, thank you!
Wait, I actually got a little bit ahead of myself. I still love you man, I truly do, but I am faced with another slightly little situation: if i use ->stock, it says 0.000000. If i use total_stock, it shows the actual stock, but it doesn’t drop together with the variations dropping (for example I have 100 numbers, I buy one and it dissapears from the dropdown-thing seleciton, but the code you gave me still says 100.)
any clue to how could I fix this?
I tried get_stock_quantity, etc.
Nope, nope, nevermind, the total_stock was correct, I just had to make some different setting.
THANK YOU! Very very much.
This was just the code I was looking for.. .thank you ??
The only thing.. if I use the first code I get 3.000000 in stead of 3 for the stock If I use the code with the total_stock no stock is display. I have single products. How do I get rid of all the extra 0000. For Dutch it looks like 3 miljon are on stock instead of just 3 ??
At WooCOmmerce settings I set the decimalseperator to, and the thousand seperator to . like dutch standards. But stock is still showing 3.000000 for 3Simply use some php magic to remove decimals…
echo ‘Stock :’.number_format($product->stock,0,”,”);
@ollbrettfahrer77 – If I use that, the number is “0” and not the actual stock number
Thank you!!
@aofmarketing this worked for me:function shop_inventory(){ global $product; {echo 'Available: '.number_format($product->stock,0,'','');} }; add_action( 'woocommerce_after_shop_loop_item_title', 'shop_inventory' );
Now I just need to figure out how to show/remove from certain categories…
(not wanting to hijack the thread – but if any of you took it to the next level, could you please let me know? Thanks!)@littlebizonline – what about something like this? Not sure what you would want to echo on the products that don’t have stock, if anything, so I left the “else” blank, make that what you want
<?php if ( is_product_category() ) { if ( is_product_category( 'category1' ) ) { echo '.number_format($product->stock,0,'',''); } elseif ( is_product_category( 'category2' ) ) { echo '.number_format($product->stock,0,'',''); } else { echo ''; } } ?>
lorro, you are a genius and more than likely a wonderful person. Thanks for the code.
Thanks @aofmarketing for coming back to me, but unfortunately this isn’t working (possibly because my php skills are still pretty basic!)
Would you mind terribly trying to populate this for me so that:
“Lighting” and “Vases” display stock as above, but “Styling” shows no mention of this?
We do not need to worry about anything having 0 stock, as this is a quoting site so stock doesn’t actually deplete at all.Thank you!
Nice piece of coding thanks! I used the following code to show the remaining stock items of my products on this page: https://www.decreatieveschool.nl/schoolkalender/
function shop_inventory(){ global $product; {echo 'Available: '.number_format($product->stock,0,'','');} }; add_action( 'woocommerce_after_shop_loop_item_title', 'shop_inventory' );
But it does not really work the way I want it to work. So I was wondering if someone could help me with this. I am willing to pay if you create for me a little code piece that does the following:
– Show the remaining stock items only if the stock is smaller than 5.
– Show it on the next line (see the link to the page above to see what I mean).
– Make it bold text and in red.
– If the stock reaches 0, it should say: Uitverkocht! (That means sold out :))It would be great if someone could help me out here!
Kind regards,
Eric Smeets.
- The topic ‘Display stock availabilty on shop page, WooCommerce’ is closed to new replies.