How to display only the last 3 items in stock

  • Posts: 142
  • Thank you received: 3
  • Hikashop Business
1 year 9 months ago #342735

-- HikaShop version -- : HikaShop Business 4.6.0
-- Joomla version -- : 4.1.5
-- PHP version -- : 7.4.29

Hi
I need to hide the stock of my products as long there are more than 3 Items in Stock.
If the stock goes down to 3 then I want customer to see that there are only 3 Items left.
How can I do that?

Please Log in or Create an account to join the conversation.

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
1 year 9 months ago #342746

Hi,

Normally, the stock should already automatically display on the frontend.
So it's just a matter of hiding the stock above a certain amount.

On the product details page, it's the view file product / quantity.php (you can find it in the menu Display>Views) which displays the stock with this code:

if(!empty($this->row->product_stock_message))
		echo JText::sprintf($this->row->product_stock_message, $stock);
	elseif($stock > 0)
		echo (($stock == 1 && JText::_('X_ITEM_IN_STOCK') != 'X_ITEM_IN_STOCK') ? JText::sprintf('X_ITEM_IN_STOCK', $stock) : JText::sprintf('X_ITEMS_IN_STOCK', $stock));
	elseif(!$in_stock)
		echo JText::_('NO_STOCK');
So you could adapt the code:
if(!empty($this->row->product_stock_message))
		echo JText::sprintf($this->row->product_stock_message, $stock);
	elseif($stock > 3)
		echo '';
	elseif($stock > 0)
		echo (($stock == 1 && JText::_('X_ITEM_IN_STOCK') != 'X_ITEM_IN_STOCK') ? JText::sprintf('X_ITEM_IN_STOCK', $stock) : JText::sprintf('X_ITEMS_IN_STOCK', $stock));
	elseif(!$in_stock)
		echo JText::_('NO_STOCK');
and for the listings, it should be something similar in the file product / add_to_cart_ajax.php

The following user(s) said Thank You: ePower2007

Please Log in or Create an account to join the conversation.

  • Posts: 142
  • Thank you received: 3
  • Hikashop Business
1 year 9 months ago #342795

Thanks a lot!
worked!

Please Log in or Create an account to join the conversation.

Time to create page: 0.058 seconds
Powered by Kunena Forum