# "Shuffle" Sorting That Changes Daily

> Adds a random order option to the shop sorting that stays the same all day, so pagination works and every product gets its turn at the top.

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

## Code

```php
$wpide_shuffle_default = false; // Make shuffle the default order.

add_filter( 'woocommerce_catalog_orderby', function ( $options ) {
    $options['shuffle'] = 'Discover (random)';

    return $options;
} );

add_filter( 'woocommerce_get_catalog_ordering_args', function ( $args, $orderby ) {
    if ( 'shuffle' === $orderby ) {
        $args['orderby']  = 'RAND(' . absint( current_time( 'Ymd' ) ) . ')';
        $args['order']    = '';
        $args['meta_key'] = ''; // phpcs:ignore WordPress.DB.SlowDBQuery
    }

    return $args;
}, 10, 2 );

if ( $wpide_shuffle_default ) {
    add_filter( 'woocommerce_default_catalog_orderby', function () {
        return 'shuffle';
    } );
}
```

## Notes

Set $wpide_shuffle_default to true to make it the default order for the shop.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find ""Shuffle" Sorting That Changes Daily" 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/
