Skip to content

Instantly share code, notes, and snippets.

@bekarice
Created July 28, 2016 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bekarice/bac8b67064001ebc3bc2475424d99f87 to your computer and use it in GitHub Desktop.
Save bekarice/bac8b67064001ebc3bc2475424d99f87 to your computer and use it in GitHub Desktop.
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