• Resolved alecody

    (@alecody)


    Hello,
    I need to be able to display inventory on the product page graphically and not as a number.
    For example:
    stock greater than 15 pieces = green icon
    stock greater than 2 and less than 15 pieces = yellow icon
    Stock less than 2 pieces = red icon

    How can I do this?
    Thank you

    Alessandro

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello @alecody

    Hi alecody (@alecody

    You can show the stock graphically by overriding the woocommerce stock template into the active theme. After then upload your images to the folder or else upload from the admin panel in media and copy the image or graphics path. Follow the below steps to the overriding stock template.

    1. Go to wp-content/plugins/woocommerce/templates/single-product and copy stock.php

    2. Now go to wp-content/themes/{YOUR_ACTIVE_THEME}/woocommerce/single-product/ and paste stock.php here.

    3. Enable stock from the product: https://prnt.sc/EXvfnD5wZ9s4

    If you didn’t override any woocommerce template in the active theme then please create a directory as mentioned in the above path in the active theme.

    In stock.php file, you can set your conditions like,

    <?php
    	 global $product; 
    	$stock  = $product->get_stock_quantity(); 
    	if($stock > 15){
    		?>
    			<img src="{IMG_PATH_GREEN}"/>
    		<?php
    	}else if($stock > 2 && $stock < 15){
    		?>
    			<img src="{IMG_PATH_YELLOW}"/>
    		<?php
    	}
    	}else if($stock > 2){
    		?>
    			<img src="{IMG_PATH_RED}"/>
    		<?php
    	}
    	?>
    

    You can put the above code in stock.php or other places you want to show on the product page.

    Thank You.

    Thread Starter alecody

    (@alecody)

    @webdesksolution you are an angel!
    I will try what you recommended and let you know.
    Most kind!
    Ale

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘view stocks graphically’ is closed to new replies.