Displaying Magento Backorder Availability on Product Pages
As an e-commerce store owner using Magento, you may have enabled backorders for some of your products to ensure continuous inventory management during stockouts. By default, Magento displays “In Stock” even when a product is out of stock but allows backorders.
However, this inconsistency in messaging can confuse customers when they add the item to their cart and only then see a notification about the backorder status. To provide transparency upfront, you may want to update the product page to directly display the backorder message instead of “In Stock”.
Understanding Magento’s Default Behavior
In your Magento installation, the stock availability is determined by the cataloginventory/stock_item table. The is_in_stock column indicates whether a product is currently in stock or not.
By default, if is_in_stock is 1 (true), Magento displays “In Stock” on the product page regardless of the backorder status defined under the Inventory > Manage Stock > Allow Backorders setting for that particular product.
Changing the Product Page Display
To modify this behavior and display the backorder message directly on the product page, you’ll need to customize the Magento template files. Here’s a step-by-step guide:
-
Locate the Product View Template
Navigate to your Magento theme directory (usually
app/design/frontend/<vendor>/<theme>) and find thecatalog/product/view.phtmlfile. -
Update the Stock Availability Display
In the
view.phtml, locate the following section:
<?php if ($this->getProduct()->isAvailable()): ?>
<p class="availability in-stock"><?= /* @escapeNotVerified */ $block->getAvailabilityDescription() ?></p>
<?php else: ?>
<p class="availability out-of-stock"><?= /* @escapeNotVerified */ $block->getUnavailableDescription() ?></p>
<?php endif; ?>
-
Add Custom Logic for Backordered Products
To check if a product is backorder-enabled, you can use the
allow_backorderssetting from thecataloginventory/stock_itemtable:
<?php $backorder = $this->getProduct()->getStockItem()->getAllowBackorders(); ?>
<?php if ($this->getProduct()->isAvailable()): ?>
<p class="availability in-stock"><?= /* @escapeNotVerified */ $block->getAvailabilityDescription() ?></p>
<?php elseif($backorder && !$this->getProduct()->isAvailable()): ?>
<p class="availability back-order"><?= /* @escapeNotVerified */ 'This item is currently on backorder.' ?></p>
<?php else: ?>
<p class="availability out-of-stock"><?= /* @escapeNotVerified */ $block->getUnavailableDescription() ?></p>
<?php endif; ?>
-
Add CSS for the Backorder Class
To style the new “Back Order” message, add a CSS rule in your theme’s
cssfolder:
.back-order {
color: red;
font-weight: bold;
}
Conclusion
By following this guide, you can successfully update your Magento product pages to display backorder messages directly instead of showing “In Stock”. This transparency helps manage customer expectations and improves the overall shopping experience.
Remember, whenever you need more advanced customizations or support for Magento development, consider reaching out to professional services like those offered by Laravel Company.
This modification ensures that your product pages provide accurate inventory status information from the moment a customer lands on a product listing.