Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WooCommerce: Add random product sorting option to shop / archives
<?php // only copy if needed
/**
* Adds randomized product sorting option to WooCommerce stores (WC 2.3+)
*
* @param array $sortby the orderby options for product sorting
* @return array - updated sorting options
*/
function sv_random_woocommerce_catalog_orderby( $sortby ) {
$sortby['rand'] = __( 'Sort by: random order', 'my-textdomain' );
return $sortby;
}
add_filter( 'woocommerce_catalog_orderby', 'sv_random_woocommerce_catalog_orderby' );
add_filter( 'woocommerce_default_catalog_orderby_options', 'sv_random_woocommerce_catalog_orderby' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.