Stock Status aka $stock in OpenCart – How to stylize Stock Status

May 02, 2013 photography

A quick guide to stylize Stock Status in OpenCart

You can customize the Stock Status text in OpenCart via the admin panel. If you aren’t sure how just go to System > Localisation > Stock Statuses

Easy enough. But what if you want to stylize the In Stock vs Out of Stock. Simple CSS won’t work! That stylizes both In Stock and Out of Stock.

You will have to dig a little deeper. Go to theme > template > product > product.tpl

Find line 48 or depending on your version <div class=”padd-avalib”>  see the echo $stock; that is where it is displaying either in stock or out of stock. Now you need a little if statement to write a style specifically for the out of stock. Normally you would expect the if statement to be something like :

<?php if ($stock == 0){
echo '<span style="color:red;">'.$stock.'</span>';
}else{echo $stock;} ?>

But turns out $stock isn’t based on a number at all, at least not with Version 1.5.3.1
It is based on the term/string that you have in your admin section. So you will need:

<?php if ($stock == "Sold Out"){
echo '<span style="color:red;">'.$stock.'</span>';
}else{echo $stock;} ?>