I have 3 products in woocommerce that I wish to sell and show how many left in stock for each one. The rest of the website is not stock controlled.
I do not want to show a label that says 745 in stock or whatever for all of them as they are always in stock. Just the clearance or on sale items in my one and only page.
The code below achieves this.
1 2 3 4 5 6 7 8 9 10 11 12 |
add_action('woocommerce_after_shop_loop_item','bbloomer_show_stock_shop', 10); function bbloomer_show_stock_shop() { global $product; if ( $product->stock ) { // if manage stock is enabled if ( number_format( $product->stock,0,'','' ) < 4 ) { // if stock is low echo '<div class="remaining">Only ' . number_format($product->stock,0,'','') . ' left in stock!</div>'; } } } |
Add the code to the functions.php
With thanks to this site for this great code https://www.businessbloomer.com/woocommerce-add-stock-quantity-on-shop-page/