How to visualize on frontend as: 10+ in stock in Woocommerce.

If you state the number of stocks in your webshop, you may want to limit the number if the number of stocks exceeds a certain number. Eg 10. here I have a function that can show quantity in stock if the product is in stock. If the product is not in stock, it says “Out of stock.

Sådan visualiseres på frontend som: 10+ på lager i Woocommerce.
hvis du oplyser lagerantal i din webshop så kan det være at du ønsker at begrænse antallet hvis lagerantallet overstiger et hvis antal. Fx 10. her har jeg en funktion som kan vise antal på lager, hvis produktet er på lager. Er produktet ikke på lager skriver den “Ikke på lager.

/*--------------------------------------------------------------
Single-product availability @@ lennartc
--------------------------------------------------------------*/
function wcStock($availability)
{
    global $product;
	if ($availability === 'outofstock') {
	echo '' . __('Produktet er i øjeblikket ikke tilgængelig', 'cco') . '';
	}
	if ($availability === 'instock') {
	    	    $antal = $product->get_stock_quantity();
	    	    if ($antal > 10) {
			        $antal = '10+';
                }
	echo '<span  class="your_styles">';
	    	    echo $antal ? $antal . ' ' : ''; echo __('På lager', 'cco') .' - '. __('Hurtig levering', 'cco') .'</span>';
	}
}

The above code can be used and you can edit in it. The texts are in Danish and can be translated with your theme’s textdomain, in the above example ‘cco’.

Use the function as follows:

Ovenstående kode kan bruges og du kan redigere i den. Teksterne er på dansk og kan oversættes med dit tema’s tekstdomæne, i ovenstående eksempel ‘cco’.

Brug funktionen sådan:

 wcStock($product->get_stock_status());