# Different Default Sorting per Category

> Sets the default product order for specific categories, for example newest first for "New arrivals" and price for "Clearance", while others keep the store default.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, sorting, categories
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-category-default-sorting/

## Code

```php
$wpide_category_sorting = array( // Category slug => default sorting.
    'new-arrivals' => 'date',
    'clearance'    => 'price',
);

add_filter( 'woocommerce_default_catalog_orderby', function ( $orderby ) use ( $wpide_category_sorting ) {
    if ( ! is_product_category() ) {
        return $orderby;
    }

    $term = get_queried_object();

    return ( $term && isset( $wpide_category_sorting[ $term->slug ] ) ) ? $wpide_category_sorting[ $term->slug ] : $orderby;
} );
```

## Notes

Values are the sorting keys WooCommerce uses: menu_order, popularity, rating, date, price, price-desc.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Different Default Sorting per Category" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
