↳ Notes

Changing the default product sorting in WooCommerce

Recently I was working on changing the default product sorting on an e-shop. The new default sorting was to be by price, from lowest. The sorting is changed here: Appearance – Customize – WooCommerce – Product Catalog. In my case I chose Sort by price (ascending) and that was it?

WooCommerce product sorting

The products did start sorting by price from lowest, but some products that are currently unavailable popped up too. Fortunately, these products can be hidden very easily. In the WooCommerce – Settings – Products – Inventory section there’s the Hide out of stock items from the catalog option.

WooCommerce hide out of stock products

But what if you don’t want to hide these products, only push them to the end of the list? So that they don’t distract the customer on the first pages, but are still available as a teaser that you carry something like that. In this case I had to reach into the code. Into the functions.php file in your active child theme, write the following code.

The code modifies the query on the products table and sets the primary sorting by stock status (in/out of stock) and the secondary by price from lowest. One more thing – careful! For it to work, you have to switch the product sorting to Default sorting (custom ordering + name) (see the first image).

Need this on your own shop?

I do these edits on client shops - from small tweaks at checkout to custom payment gateways. Indicative prices are written down, so you know what you are getting into.

Pricing for edits →

Comments

No comments yet. Be the first.

Leave a comment

By submitting a comment you give me your name, and your IP address is also stored for technical reasons (I delete it after a year). I store your email only if you tick follow comments; an unconfirmed subscription is deleted after a week together with the email, a confirmed one is kept until you unsubscribe. Details in the privacy policy →

I approve comments manually; yours will appear once approved.