Changing the order of products in WooCommerce

WooCommerce offers several default sorting options for products, including:

  • Sort by popularity
  • Sort by average rating
  • Sort by latest
  • Sort by price: low to high
  • Sort by price: high to low

However, a more user-friendly approach is to prioritize in-stock and/or featured products. This guide will walk you through enabling these features using FiboFilters.

Note:
Both features can function simultaneously.

Table of Contents

Show in-stock products first

FiboFilters provides a built-in feature to prioritize in-stock products and push out-of-stock items to the end of the list. By default, this feature is disabled, but you can enable it by adding the following PHP snippet to your website:

add_filter( 'fibofilters/config/override_ordering_enabled', '__return_true' );
add_filter( 'fibofilters/request/product_order/in_stock_first', '__return_true' );

Learn how to add this snippet to your WordPress.

Once enabled, in-stock and on-backorder products will appear first, followed by out-of-stock items, as shown in the example below:

Customize stock status priorities

You can customize the display order of products based on their stock status using the following filter:

add_filter( 'fibofilters/product_order/stock_status_priorities', function ( $priorities ) {
	$priorities['instock'] = 10;
	$priorities['onbackorder'] = 5;
	$priorities['outofstock'] = 1;
	return $priorities;
} );

Learn how to add this snippet to your WordPress.

In this example, products that are in stock will be shown first, followed by those on backorder, and finally those that are out of stock.

Higher values indicate higher priority, meaning those products appear earlier in the list. By default, both in-stock and on-backorder products have a priority of 5, while out-of-stock products have a priority of 1.

This filter also supports custom stock statuses, allowing you to define priorities for any additional statuses you may be using:

add_filter( 'fibofilters/product_order/stock_status_priorities', function ( $priorities ) {
	$priorities['customstatus'] = 100;
	return $priorities;
} );

Learn how to add this snippet to your WordPress.

To prioritize featured products, add the following code to your website:

add_filter( 'fibofilters/request/product_order/featured_first', '__return_true' );

Learn how to add this snippet to your WordPress.

After adding this snippet, featured products will be displayed at the top of the product list, providing better visibility for special items:

FiboFilters: show featured products first

By implementing these features, you can improve the shopping experience by presenting products in a more intuitive and customer-friendly order.

Disabling in-stock-first sorting for specific ordering

When in-stock-first sorting is enabled, FiboFilters prioritizes product stock status in the following order:

  1. in-stock products
  2. on-backorder products
  3. out-of-stock products

If you then order products by price, FiboFilters will show in-stock products ordered by price first, followed by on-backorder products by price, and finally out-of-stock products by price.

However, this may not always be the desired outcome. You can disable in-stock-first sorting for specific sorting options.

To disable in-stock-first sorting for certain sorting types (e.g., sorting by price), use the following filter:

add_filter( 'fibofilters/request/product_order/in_stock_first_exceptions', fn() => [ 'price', 'price-desc' ] );

Learn how to add this snippet to your WordPress.

You can apply this to any of the following sorting types:

  • 'menu_order'
  • 'popularity'
  • 'rating'
  • 'date'
  • 'price'
  • 'price-desc'
  • 'modified-desc'
  • 'title'
  • 'title-desc'
  • 'relevance'

Disabling featured-first sorting for specific ordering

Similarly, you may want to disable the featured-first sorting for certain ordering types.

To do this, apply the following filter:

add_filter( 'fibofilters/request/product_order/featured_first_exceptions', fn() => [ 'price', 'price-desc' ] );

Learn how to add this snippet to your WordPress.

Again, replace 'price' and 'price-desc' with your choices.