Page 1 of 2
"Out Of Stock" text colour change
Posted: Fri Feb 18, 2011 6:23 pm
by Phil
Hi All,
Firstly I just want to say that I think this forum is amazing, I am currently in the process of changing our current website over to opencart and have found endless support using this forum and think that opencart itself is brilliant.
Anyway, I have checked this forum for the last hour or so and cant see any posts that tell me how I can change the colour of the "Out Of Stock" text on the products page, I would like to have the text in red, but
only if the product is out of stock?? i.e " In Stock" = Black "Out Of Stock" = Red...... Is this possible, my current test store is located at
http://www.pandorasjewellerybox.co.uk/store/ version 1.4.9
Any help is much appreciated.
Thanks,
Phil
Re: "Out Of Stock" text colour change
Posted: Fri Feb 18, 2011 7:14 pm
by kedgetech
You can check the text coming on the product tpl file and change the color to red. We did the same for pre-order. see below.
http://www.opencartaustralia.com/sales/ ... duct_id=30
Re: "Out Of Stock" text colour change
Posted: Fri Feb 18, 2011 10:18 pm
by Phil
Thanks, for the quick response.
I have just looked at your pre-order as suggested and that is exactly what I would like to do, I'm just not sure how to do it??
I have looked in the product.tpl file and can't see what I am supposed to change.....
Code: Select all
<tr>
<td><b><?php echo $text_availability; ?></b></td>
<td><?php echo $stock; ?></td>
</tr>
I'm assuming that this is the control for the stock status displayed but I'm not sure what I am meant to add so that only "out of stock" shows up in red?
Thanks again for your help.
Phil
Re: "Out Of Stock" text colour change
Posted: Sun Feb 20, 2011 4:47 am
by kedgetech
Very simple if the coming value is equal to PRE-ORDER change the color jazz it up with red if not follow the usual logic. You just need to add a if condition and then color the text. Thats all.
Re: "Out Of Stock" text colour change
Posted: Sun Feb 20, 2011 8:26 am
by Phil
Many thanks for your help, all is now sorted.
Phil
Re: "Out Of Stock" text colour change
Posted: Thu Mar 03, 2011 10:03 am
by Erunix
I register simply because I was actually searching for more info on items in carts, search, and some other functions and came across this post.
Is great Phil found the solution, and Kedgetech point him on the path to solve his problem. The only thing I saw is that other people with this issue might not be coders, maybe they are just the designer, also taking in consideration the new coders. I just simply give them a view of what the code should do.
Here my fellow OpenCarters:
Code: Select all
<td><b><?php echo $text_availability; ?></b></td>
<?php if($stock >= 11){
$wcd_color_stock = '#006633';
} elseif($stock <= 10 && $stock >= 5){
$wcd_color_stock = '#FF9900';
} elseif($stock <= 4 || $stock == 'SOLD OUT'){
$wcd_color_stock = '#990033';
}
?>
<td><span style="font-size:12px;font-weight:bolder;color:<?php echo $wcd_color_stock; ?>;"><?php echo $stock; ?></span></td>
Enjoy.
Re: "Out Of Stock" text colour change
Posted: Thu Mar 03, 2011 2:01 pm
by kedgetech
@Erunix - You the man

Thanks.
Re: "Out Of Stock" text colour change
Posted: Mon Dec 26, 2011 2:40 pm
by bassdude
Erunix wrote:I register simply because I was actually searching for more info on items in carts, search, and some other functions and came across this post.
Is great Phil found the solution, and Kedgetech point him on the path to solve his problem. The only thing I saw is that other people with this issue might not be coders, maybe they are just the designer, also taking in consideration the new coders. I just simply give them a view of what the code should do.
Here my fellow OpenCarters:
Code: Select all
<td><b><?php echo $text_availability; ?></b></td>
<?php if($stock >= 11){
$wcd_color_stock = '#006633';
} elseif($stock <= 10 && $stock >= 5){
$wcd_color_stock = '#FF9900';
} elseif($stock <= 4 || $stock == 'SOLD OUT'){
$wcd_color_stock = '#990033';
}
?>
<td><span style="font-size:12px;font-weight:bolder;color:<?php echo $wcd_color_stock; ?>;"><?php echo $stock; ?></span></td>
Enjoy.
hi. that is very usfull thanks. but also where would i find the tpl to be able to edit this?
Re: "Out Of Stock" text colour change
Posted: Mon Jan 16, 2012 11:26 pm
by spharx
You find it in /catalog/view/theme/YOU THEME/template/product
Got a question tho:
The code works perfecly if you use stock levels as numbers, but how do i make it work with text instead? I have choosen to not show stock level from admin so it just show "in stock" instead, but then the color is not working.
/Spharx
Re: "Out Of Stock" text colour change
Posted: Tue Jan 17, 2012 3:48 am
by spharx
anyone?
Re: "Out Of Stock" text colour change
Posted: Sun Jan 22, 2012 7:27 am
by markisonfire
This is a simple version that works for me, it is only red when something is out of stock.
In /catalog/view/theme/default/template/product/product.tpl, find:
Code: Select all
<span><?php echo $text_stock; ?></span> <?php echo $stock; ?></div>
And replace it with:
Code: Select all
<span><?php echo $text_stock; ?></span>
<?php if($stock >= 1) {
$my_color_stock = '#000';
} elseif($stock < 1) {
$my_color_stock = 'red';
}
?>
<span style="color: <?php echo $my_color_stock ?>;"><?php echo $stock; ?></span></div>
I also have the code if you're using the Shoppica theme, so let me know if you need/want it.
Re: "Out Of Stock" text colour change
Posted: Sat Feb 04, 2012 5:59 pm
by vallentin24
can you post that code for shoppica theme?
thank you
Re: "Out Of Stock" text colour change
Posted: Fri Feb 10, 2012 8:06 pm
by temptious
markisonfire wrote:This is a simple version that works for me, it is only red when something is out of stock.
In /catalog/view/theme/default/template/product/product.tpl, find:
Code: Select all
<span><?php echo $text_stock; ?></span> <?php echo $stock; ?></div>
And replace it with:
Code: Select all
<span><?php echo $text_stock; ?></span>
<?php if($stock >= 1) {
$my_color_stock = '#000';
} elseif($stock < 1) {
$my_color_stock = 'red';
}
?>
<span style="color: <?php echo $my_color_stock ?>;"><?php echo $stock; ?></span></div>
I also have the code if you're using the Shoppica theme, so let me know if you need/want it.
Can this code be modified to replace the text for images?
Re: "Out Of Stock" text colour change
Posted: Tue Feb 21, 2012 2:24 pm
by markisonfire
temptious wrote:markisonfire wrote:This is a simple version that works for me, it is only red when something is out of stock.
In /catalog/view/theme/default/template/product/product.tpl, find:
Code: Select all
<span><?php echo $text_stock; ?></span> <?php echo $stock; ?></div>
And replace it with:
Code: Select all
<span><?php echo $text_stock; ?></span>
<?php if($stock >= 1) {
$my_color_stock = '#000';
} elseif($stock < 1) {
$my_color_stock = 'red';
}
?>
<span style="color: <?php echo $my_color_stock ?>;"><?php echo $stock; ?></span></div>
I also have the code if you're using the Shoppica theme, so let me know if you need/want it.
Can this code be modified to replace the text for images?
I'm not sure what you mean, please elaborate?
Re: "Out Of Stock" text colour change
Posted: Fri Mar 09, 2012 7:34 pm
by Joxe
Hello,
I'm also interested in changing the out of stock text in red colour and I tried the markisonfire's solution but didn't worked
My original code is:
<tr>
<td><b><?php echo $text_availability; ?></b></td>
<td><?php echo $stock; ?></td>
</tr>
Any help please? Thanks!

PS: OC v. 1.4.9.6
Re: "Out Of Stock" text colour change
Posted: Wed Mar 14, 2012 5:45 am
by Joxe
Any one please?.....
Re: "Out Of Stock" text colour change
Posted: Wed Mar 14, 2012 9:57 am
by eka7a
Joxe wrote:Hello,
I'm also interested in changing the out of stock text in red colour and I tried the markisonfire's solution but didn't worked
My original code is:
<tr>
<td><b><?php echo $text_availability; ?></b></td>
<td><?php echo $stock; ?></td>
</tr>
Any help please? Thanks!

PS: OC v. 1.4.9.6
you use it for 1.4.9.6
http://forum.opencart.com/viewtopic.php ... 23#p138711
Re: "Out Of Stock" text colour change
Posted: Sun Apr 15, 2012 3:21 am
by zreon
spharx wrote:You find it in /catalog/view/theme/YOU THEME/template/product
Got a question tho:
The code works perfecly if you use stock levels as numbers, but how do i make it work with text instead? I have choosen to not show stock level from admin so it just show "in stock" instead, but then the color is not working.
/Spharx
Thats exactly what I needed. Well this is what I came up with and it is working for me in 1.5.2.1.
Code: Select all
<span><?php echo $text_stock; ?></span>
<?php if($stock == "In Stock") {
$my_color_stock = '#000';
} elseif($stock == "Out of stock") {
$my_color_stock = 'red';
}
?>
<span style="color: <?php echo $my_color_stock ?>;"><?php echo $stock; ?></span></div>
Re: "Out Of Stock" text colour change
Posted: Sun Apr 15, 2012 6:14 am
by Joxe
Sorry, I did not understand...
Re: "Out Of Stock" text colour change
Posted: Sun Sep 16, 2012 7:16 am
by CapriBlue
I tried for 1.5.4.1
The "Out of Stock "color changed as Red but the "in stock" also became Red.
I tried to fix it and changed the part $my_color_stock='#00000'; or just 'black';
but didn't work.
So, on my site, both Out of Stock and In Stock are red color.
Do you have any idea to fix?