I am trying to figure a way to hide show stock status/availability on product page unless it is out of stock. I have all the settings configured to where it displays stock status on front end as normal, however I don't want to show "In Stock" only if the item is out of stock then I want it to display Availability "Out of Stock" only. A lot of our items are ordered through other vendors and drop shipped to customer therefore I don't want to display stock status on those items. Only the items we exclusively ship from our location.
1 Answer
To hide stock status on "In Stock" products, you can comment code for instock in following file:
app/design/frontend/{{Theme_Package}}/{{Theme_Name}}/template/catalog/product/view/type/availability/default.phtml
code will be look like after Changes:
$_product = $this->getProduct(); ?>
<?php if ($this->displayProductStockStatus()): ?>
<?php if ($_product->isAvailable()): ?>
<!-- <p class="availability in-stock">
<span class="label"><?php echo $this->helper('catalog')->__('Availability:') ?></span>
<span class="value"><?php echo $this->helper('catalog')->__('In stock') ?></span>
</p> -->
<?php else: ?>
<p class="availability out-of-stock">
<span class="label"><?php echo $this->helper('catalog')->__('Availability:') ?></span>
<span class="value"><?php echo $this->helper('catalog')->__('Out of stock') ?></span>
</p>
<?php endif; ?>
Now Stock status shows only on Out of Stock Products
-
Thanks, It Works, Just what I was looking for. Now I need to change the color to red or make it bolder to where it will stand out some. Text is small and light. Need it to be seen since the add to cart is missing and they wonder why there is no way to checkout– Troy B.Oct 19, 2018 at 22:57
-
-
Will this same code work on a Magento 2 Site once we complete and launch. If so what folder location and file.– Troy B.Oct 21, 2018 at 11:51
-
For Magento 2 you will find that file here, but you need to copy that file in your theme. Please copy "default.phtml" file from "/vendor/magento/module-catalog/view/frontend/templates/product/view/type" and paste it here: "/app/design/frontend/{{Theme_Package}}/{{Theme_Name}}/Magento_Catalog/templates/product/view/type/" Oct 22, 2018 at 4:02
view.phtml
code here