Created
July 28, 2016 18:02
-
-
Save bekarice/bac8b67064001ebc3bc2475424d99f87 to your computer and use it in GitHub Desktop.
WooCommerce: Add random product sorting option to shop / archives
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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