Show “Out of stock” products at the end of the WooCommerce loop

WooCommerce allows product sorting by the default criteria:

  1. Sort by popularity
  2. Sort by average rating
  3. Sort by latest
  4. Sort by price: low to high
  5. Sort by price: high to low

Unfortunately, in both cases the “in stock” and “out of stock” products are mixed together. A more UX-friendly approach will be to first show “in stock” products. To achieve this, it’s necessary to first apply  “stock status” sorting and then sorting eg. “by latest”. 

FiboFilters has a built-in solution that lets you prioritize the “in stock” status and display such products first.

The feature is disabled by default. To turn it on, add this PHP snippet to your functions.php in a child theme.

add_filter('fibofilters/request/base_product_ids/order_by_stock_status', '__return_true');

As a result, users should see “in-stock” products first, then “out-of-stock” products as in the screenshot below.