How To Enable Magento 2 Out Of Stock Add To Cart Function

by admin

How to enable Magento 2 out of stock add to cart function, or how to display the Add to Cart button for out of stock products. Read this article to learn!

Disappointing is an understatement when visitors encounter an “out of stock” product on your website.

In fact, $22 billion is lost every year due to the stock-out status. Not to mention customers are more likely to bounce off your website and hurt your SEO.

To avoid losing customers due to out-of-stock problems, some store owners want to display the Add to Cart button for out-of-stock products.

However, the default Magento doesn’t support this function, and it’s very complicated to enable it.

So in this article, we will show you how to enable the Magento 2 Out Of Stock Add To Cart function.

Moreover, we will introduce you to 2 better solutions to solve the stock issue.

Let’s get started! 

How To Enable Magento 2 Out Of Stock Add To Cart Function

out-of-stock

To display the Add to Cart button for out of stock products on Magento, you need to follow these steps:

  1. Navigate to System > Configuration > Catalog > Inventory, and set Backorders to Allow Qty Below 0.
  2. Navigate to System > Configuration > Catalog > Inventory > Stock Options, and set Display Out of Stock Products to Yes.
  3. Run SQL statement

Because Magento doesn’t allow you to change the Qty for Item’s Status to Become Out of Stock option to go below 0 (it doesn’t allow you to enter a negative value in this field), you need to run the following SQL statement from your phpmyadmin panel:

UPDATE core_config_data SET value = ‘-1’ WHERE path = ‘cataloginventory/item_options/min_qty’;

  1. Verify the setting has been added

Navigate to System > Configuration > Catalog > Inventory to verify that Qty for Item’s Status to Become Out of Stock is now -1 (a negative value).

  1. Set all store products to In stock

Navigate to Catalog > Manage Products.

Select all products, then select Actions > Update Attributes > Submit.

Select Inventory then set Stock Availability to In Stock.

Click Save.

  1. Re-index all indexes.
  2. Set the new out-of-stock rule

Now that all products are In Stock, you need to set a new rule that the product is Out of stock when the value goes below zero (the previous setting is -1 [minus one]). This is necessary to modify the theme in the front end.

list.phtml and view.phtml both contain IF statements that create a condition that if the product is “In Stock,” then displays the Add to cart. You need to remove it because the website has been modified in order to display all products.

Change the code:

<div class="add-to-box">
  <?php if($_product->isSaleable()): ?>     
  <?php echo $this->getChildHtml('addtocart') ?>
  <?php endif; ?>
</div>

To the code:

<div class="add-to-box">
<?php echo $this->getChildHtml('addtocart') ?>
</div>

An another way to display Out of stock and In stock using QTY and not stock status:

<?php $_product = $this->getProduct() ?>
<?php if((int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty() < 1): ?>
<p><strong>
  <?php echo $this->__('Out of stock') ?>
</strong></p>
<?php else: ?>
<p>
  <?php echo $this->__('In Stock')?>
</p>
<?php endif; ?> 

The Drawback Of Magento 2 Out Of Stock Add To Cart Function

cons

As you can see, it’s very time-consuming to enable Magento 2 Out Of Stock Add To Cart Function function to display the Add to Cart button for out-of-stock products.

Magento 2 Out Of Stock Add To Cart is a way to avoid losing potential customers due to out-of-stock problems. But it’s not a great way.

First of all, if you don’t make it clear that the product is out of stock, your customers might get angry when they find out that they have ordered an out-of-stock product.

Another thing is that there will be some products you don’t want to restock or you are not sure when it will be restocked.

However, with the method above, you cannot control the out of stock items efficiently. Thus, a customer might buy an out-of-stock product that can’t be restocked soon or won’t be restocked, and it gives the customer a really bad shopping experience in your store.

So below, we want to introduce to you two better solutions for the stock-out issue to increase sales and avoid losing potential customers.

Those are:

  • Magento Backorder
  • Magento 2 Out Of Stock Notification

Better Solution #1: Magento Backorder

Magento 2 Pre Order extension is a win-win situation for both the customer and the store owner.

Backorders allow you to keep selling products even if it is out of stock.

And even though default Magento does support this function, it has many limitations.

For example, it doesn’t support inviting customers to get notified once the product is back in stock.

And it doesn’t apply to configurable products, group products and bundle products.

To optimize the Magento Backorder feature, we recommend you to install:

magento 2 pre order

Magento 2 Backorder by BSS

This extension is an amazing tool to enable pre-order and backorder in your store.

And it allows your customers to backorder the child item of a configurable product, group product or bundle product.

In addition, this module will notify your customers again on the checkout page about the pre-order and backorder products so they can be fully aware. It can help build a relationship with your customer.

Full list of features:

  • Allow pre-ordering out of stock and upcoming products
  • Be able to pre-order product on the category page
  • Replace Add to Cart button with the Pre-Order button
  • Display notes and messages for pre-order products on the product page, shopping cart and order details page
  • Edit Magento 2 Pre Order notes, buttons, and messages to be shown on the frontend
  • Manage previous orders conveniently in the backend

Better Solution #2: Magento 2 Out Of Stock Notification

Magento 2 Out Of Stock Notification is a great way to allow your customers to subscribe to the back in stock email for the product they want but is out of stock. Thanks to that, customers can come back to buy what they want when the product is available.

Once again, default Magento does support this function. But the default extension only allows logged-in customers to subscribe to the stock alert, which means not-logged-in customers or visitors can’t get the stock notification for the out-of-stock product.

And it doesn’t apply to the children items of configurable products, group products and bundle products.

So we want to introduce the perfect solution for Magento 2 Out Of Stock Notification and more advanced features:

magento-2-out-of-stock-notification

Magento 2 Out of Stock Notification by BSS

This module allows you to display a “Notify Me” button for the sold-out product. And it allows you to display the button on any page (product page, category page, search result page).

Furthermore, the module allows you to enable stock notification for any customer group, even not-logged-in customers or guests.

This extension also supports managing customer subscriptions effectively. You can manage customer subscribed information in a grid and edit customers’ information in that grid.

A unique feature of this extension is the Product Subscription Tab (only available to logged-in customers). On the Customer Account Page, your customers can check information about products they have subscribed to and choose to stop getting notifications.

INSTALL NOW: Magento 2 Out Of Stock Add To Cart extension by BSS!

Full list of features:

  • Enable stock update notification for guest / not-logged-in customers
  • Automatically send email notification when product is back in stock
  • Manage stock subscription in the Customer Account Page
  • Support product stock alert on Product Page/Category Page/Search Result Page
  • Allow stock alert for children product of the configurable product, grouped product and bundle product

Conclusion

In this article, we have shown you how to enable the Magento 2 Out Of Stock Add To Cart function in default Magento.

Better yet, we even introduced to you two better solutions to reduce losing potential customers due to the stock-out issue.

We hope this blog is helpful and good luck to you!

BSS Commerce is one of the leading Magento extension providers and web development services in the world. With experienced and certified Magento developers, we commit to bringing high-quality products and services to optimize your business effectively. Furthermore, we offer FREE Installation – FREE 1-year Support and FREE Lifetime Update for every Magento extension.

CONTACT NOW to let us know your problems. We are willing to support you every time.

Next Reading Suggestions

© 2019 BSS Commerce owned by THANH CONG INTER ., JSC. All Rights Reserved.
Business registration certificate no. 0106064469 issued by Hanoi Department of Planning and Investment on 19 December 2019.
Legal Representative: Mr. Nguyen Quang Trung.