When a product is out of stock, the shop automatically places it after the in-stock products in the category and in search results. You do not need to arrange anything by hand.
When a product is out of stock
A product counts as out of stock when Stock Status is set to Out of Stock. The shop sets this by itself when an order brings the quantity down to 0.

- Quantity - how many items you have.
- Stock Status - In Stock or Out of Stock.
When the product is back, enter the new quantity and set Stock Status to In Stock. The product returns to its place among the others.
Show or hide out-of-stock products
Stores › Configuration › Catalog › Inventory
Expand the Stock Options section.
For Display Out of Stock Products, first untick Use system value, otherwise the field is locked. Then choose Yes if out-of-stock products should stay visible at the end of the list, or No if they should be hidden.

First untick Use system value on the right, then choose Yes or No in the field. Click Save Config and flush the cache.


