How to Hide Out of Stock Items from WooCommerce

There are a few simple steps you need to do to hide items that are out of stock in WooCommerce. If you want to close the stocks throughout the site, you should try the second step. Or, if you just want to hide the out-of-stock products in the variations, the first step will be enough […]

How to Hide Out of Stock Items from WooCommerce

There are a few simple steps you need to do to hide items that are out of stock in WooCommerce. If you want to close the stocks throughout the site, you should try the second step. Or, if you just want to hide the out-of-stock products in the variations, the first step will be enough for you.

Deleting out of stock products from your WooCommerce website can have a negative impact on your SEO. In order for your customers not to encounter 404 pages, you can send the deleted products to the category in which the product is located with the 301 redirect function, or you can hide the products to your in-site customers by closing the stocks. In addition, instead of deleting the products that are out of stock, you can write a detailed description on the product page and inform your users about whether this product will come back to stock.

If there are few products on your site, what I explained above will be sufficient. However, if there are hundreds or even thousands of products in your store, this stock closure will become inextricable. Therefore, it is possible to hide products that are out of stock with one click. You can simply close your stocks with the 2 variations which I will share in this article.

Hiding Out-of-Stock Products in Variations

In this method, I will explain how to hide the out of stock variations of the products that are qualified on our site.

  • Login to your WordPress dashboard
  • Click the Settings tab under WooCommerce
  • Visit the Products tab above
  • Then click the Inventory tab
  • Click the Out of Stock Visibility option on the Stock tab and click the save button.

After this process, you will hide the variations of the products with variations that are out of your site.

woocommerce-stock-1
woocommerce-stock-2

Closing Stocks Across the Site

Many e-commerce sites experienced problems with their customers due to delays caused by shipping during the pandemic process that we are in. In this process, some site owners wanted to close the products on their sites for sale, but could not do this because of the excess product problem I mentioned above and had to put their sites in maintenance mode.

With the method I will share below, it is possible to shut all products on your site for sale. Since it will be necessary to edit a file on your site with this method, please make a backup of the relevant file before doing anything.

  • Connect to your site’s hosting account via CPANEL or FTP
  • Go to wp-content folder
  • Find your theme folder in wp-content
  • Open the functions.php file in your theme folder with a text editor.
  • Save the file, adding the code I shared below
  • Upload the file back to the relevant directory
add_filter('woocommerce_short_description','ts_add_text_short_descr');
function ts_add_text_short_descr($description){
$text="<span class='nostock'>Stocks are currently out of stock. An update will be made very soon.</span>";
return $description.$text;
}

Arrange phrase according to you: “Stocks are currently out of stock. Update will be done very soon. “. In addition, create a CSS in the code I opened called outofstock and add it to the View> Customize> Additional CSS field in your WordPress administration panel. For an example CSS;

.nostock {
background:#ddd;
padding:20px;
text-align:center;
}

As I mentioned above, method 2 will require some code knowledge so be careful.

This is the content I prepared about hiding out of stock WooCommerce products. If you have trouble using method 1 or 2, please let me know in the comments field.

Leave a Reply

Your email address will not be published. Required fields are marked *