Forums / Templates, Stylesheets, Page Layout / Changing the text for "0 units in stock"

Changing the text for "0 units in stock"

Started by emmathepoly on 15 Mar 2016, 5:54 AM · Views: 842

Results 1 to 8 of 8
15 Mar 2016, 5:54 AM
#1
emmathepoly avatar

emmathepoly

New Zenner

Join Date:
Dec 2015
Posts:
9
Plugin Contributions:
0

Changing the text for "0 units in stock"

Hello, I'm wanting to change the text for the product quantity on item listings. However I ONLY want to change the text when there are 0 items in stock. What I want to do is replace '0 units in stock' with something like 'this item is on backorder'. But I still want it to say 'x units in stock' if it's available.

I am using Zen Cart version 1.5.4, and my template is Responsive Sheffield Blue (https://www.zen-cart.com/showthread.php?217203-Responsive-Sheffield-Blue-v2-0). My live site can be found at battleaxegames.com. Please let me know if any other information is needed to answer my question. Thanks! :)

15 Mar 2016, 8:56 AM
#2
drint avatar

drint

New Zenner

Join Date:
Mar 2016
Posts:
14
Plugin Contributions:
0

Re: Changing the text for "0 units in stock"

You can edit the includes/templates/YOUR_TEMPLATE/templates/tpl_product_info_display.php and find the code below:

<?php echo (($flag_show_product_info_quantity == 1) ? '<li>' . $products_quantity . TEXT_PRODUCT_QUANTITY . '</li>'  : '') . "\n"; ?>

then replace with:

<?php echo (($flag_show_product_info_quantity != 1) ? sprintf('<li>%s</li>', $products_quantity > 0 ? $products_quantity . TEXT_PRODUCT_QUANTITY : 'this item is on backorder')  : '') . "\n"; ?>

cheers

15 Mar 2016, 8:58 AM
#3
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Changing the text for "0 units in stock"

In your admin > config > stock
There are several settings - but these only display when added to cart
What you want would require some custom coding

and it may have been provided

Zen-Venom Get Bitten

15 Mar 2016, 10:10 PM
#4
emmathepoly avatar

emmathepoly

New Zenner

Join Date:
Dec 2015
Posts:
9
Plugin Contributions:
0

Re: Changing the text for "0 units in stock"

DrInt:

You can edit the includes/templates/YOUR_TEMPLATE/templates/tpl_product_info_display.php and find the code below:

<?php echo (($flag_show_product_info_quantity == 1) ? '<li>' . $products_quantity . TEXT_PRODUCT_QUANTITY . '</li>' : '') . "\n"; ?>
> 
> then replace with:
> ```php
<?php echo (($flag_show_product_info_quantity != 1) ? sprintf('<li>%s</li>', $products_quantity > 0 ? $products_quantity . TEXT_PRODUCT_QUANTITY : 'this item is on backorder')  : '') . "\n"; ?>

cheers

Hello, thanks for your response! This sounds like what I need, but for some reason when I replace the code with this, it just doesn't show the quantity on the products page at all! I'm not very experienced with PHP so I'm not sure what's going wrong here. I'm not sure where to start looking either- is there anything in the template that may be messing with the code, or something in the admin panel that I need to change? Thanks!

16 Mar 2016, 12:51 AM
#5
drint avatar

drint

New Zenner

Join Date:
Mar 2016
Posts:
14
Plugin Contributions:
0

Re: Changing the text for "0 units in stock"

i didn't know the codes in your tpl_product_info_display.php file so i have no more ideas with this;
can you show me your tpl_product_info_display.php file? you can submit an attachment with your reply;

16 Mar 2016, 2:48 AM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Changing the text for "0 units in stock"

<?php echo (($flag_show_product_info_quantity != 1) ? sprintf('<li>%s</li>', $products_quantity > 0 ? $products_quantity . TEXT_PRODUCT_QUANTITY : 'this item is on backorder')  : '') . "\n"; ?>
<?php echo (($flag_show_product_info_quantity == 1) ?  sprintf('<li>%s</li>', $products_quantity > 0 ?  $products_quantity . TEXT_PRODUCT_QUANTITY : 'this item is on  backorder')  : '') . "\n"; ?>

If you inserted the above code from the first block, then change the red colored text back to what it was, then product quantity should again show except when the quantity is 0.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

16 Mar 2016, 3:52 AM
#7
drint avatar

drint

New Zenner

Join Date:
Mar 2016
Posts:
14
Plugin Contributions:
0

Re: Changing the text for "0 units in stock"

mc12345678:

<?php echo (($flag_show_product_info_quantity != 1) ? sprintf('<li>%s</li>', $products_quantity > 0 ? $products_quantity . TEXT_PRODUCT_QUANTITY : 'this item is on backorder') : '') . "\n"; ?>
> 
> ```
<?php echo (($flag_show_product_info_quantity == 1) ?  sprintf('<li>%s</li>', $products_quantity > 0 ?  $products_quantity . TEXT_PRODUCT_QUANTITY : 'this item is on  backorder')  : '') . "\n"; ?>

If you inserted the above code from the first block, then change the red colored text back to what it was, then product quantity should again show except when the quantity is 0.

thank u, i forgot change != back to ==;; :laugh:

16 Mar 2016, 4:39 AM
#8
emmathepoly avatar

emmathepoly

New Zenner

Join Date:
Dec 2015
Posts:
9
Plugin Contributions:
0

Re: Changing the text for "0 units in stock"

PERFECT! Thank you both so much! :laugh: