This How To Guide will show you how to add random order sorting to your WooCommerce shop page.
WooCommerce provides an extensive selection of options out of the box.
The shop page allows us to sort products displayed in a variety of different ways which include:
- Default sorting (custom ordering + name)
- Popularity
- Sales
- Average Rating
- Most Recent
- Price, Ascending
- Price, Descending
But what about displaying Shop page products in a random order?
If you have a lot of products, this might desirable to showcase a more extensive overview of what you offer. Each time a user views the shop page, a random-generated order of products can be displayed.
If you wish to include this feature in your WooCommerce online store, feel free to use this PHP snippet below to enable the option. Add the below code to you theme or child theme‘s functions.php file.
add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woo_catalog_ordering_args' ); function custom_woo_catalog_ordering_args( $args ) { $orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) ); if ( 'random_list' == $orderby_value ) { $args['orderby'] = 'rand'; $args['order'] = ''; $args['meta_key'] = ''; } return $args; } add_filter( 'woocommerce_default_catalog_orderby_options', 'woocommerce_catalog_random_orderby' ); add_filter( 'woocommerce_catalog_orderby', 'woocommerce_catalog_random_orderby' ); function woocommerce_catalog_random_orderby( $sortby ) { $sortby['random_list'] = 'Random'; return $sortby; }
Once you have added the code above to your active theme’s functions.php file, head to Appearance > Customise to configure your WooCommerce product catalogue sorting options.
If you are looking to launch a new website or online store for your business, request a free quote online or feel free to call me on 0468 629 301 and let’s discuss your ideas!