This article shows you how to sort items in your WooCommerce shop, and then also apply the same sort order to product category views with a PHP snippet.
Last updated: 24 Nov 2025
Reading time: 4 minutes
Sorting in WooCommerce is easy! Until it’s not.
This article shows you how to sort items in your WooCommerce shop, and then also apply the same sort order to product category views.
PLEASE NOTE:
- Your theme may dictate the sort order in other places. This article applies to WP themes like the Avada builder, which allows you to create templates that apply to specific post types and post type archives.
- You need a child theme and edit access to its functions.php file.
The problem
Although custom sorting is an option for archive pages, sorting may not be honoured in archive categories (e.g., Product Categories), and sort your products by publish date.
You might think “why not just change publish dates then?”, which may work for some, but it’s not an intuitive ordering system, and can cause you headaches when you want to schedule a product’s publish date.
Solution synopsis
Add this code snippet to your child theme to affect specific category types (post archive types), which alters the sort order on product category pages (archives).
Reorder items in the shop
To manually set the sort order of products in your shop, you can use the out of box functionality that comes standard with WooCommerce:
- Visit the Dashboard
- Click on Products in the left hand navigation.
- Select the Sorting link at the top of the product list.

This view allows you to drag products into a custom sort order. By default, they will display ascending (top to bottom order) on the frontend.
The code snippet
The ordering you did in the previous section works on the primary archive page, but doesn’t always work on the category archives, which is where this snippet does the work for you.
Add this snippet to the functions.php file of your child theme:
add_action('pre_get_posts', 'bigsalami_archive_sort_order');
function bigsalami_archive_sort_order($query)
{
if (is_archive()):
// Get queried object
$queried_object = get_queried_object();
// Check if taxonomy is defined and is set to 'product_cat'
if (isset($queried_object->taxonomy) && $queried_object->taxonomy == 'product_cat') {
$query->set('order', 'ASC'); // Sort ascending
$query->set('orderby', 'menu_order'); // Sort by menu_order (which is done in the Sorting option in WooCommerce > Products)
}
endif;
};Applying this to other post types
Not all post types have a sorting option, and this functionality is generally decided by the plugin (like WooCommerce). You can create a custom field for sorting (using a plugin like Advanced Custom Fields), and reference your custom field name for sorting in the same snippet above).
Troubleshooting
If this code does not work for you, your theme or another plugin may be dictating the sort order for your category pages, in which case you’ll need to check your unique setup and the documentation for the theme you’re using to check how to do this using their recommended methods.
Final thoughts
I hope you found this helpful, and if you require help with your implementation, please contact us.
