Forked from woogists/wc-custom-sorting-options-asc-dec.php
Last active
August 12, 2018 08:50
-
-
Save sonipb/4d4b9e3dd50e615f883055ca57b6f9c2 to your computer and use it in GitHub Desktop.
[Frontend Snippets] Custom sorting options to random (asc/desc)
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
/** | |
* Add custom sorting options (asc/desc) | |
*/ | |
add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' ); | |
function custom_woocommerce_get_catalog_ordering_args( $args ) { | |
$orderby_value = isset( $_GET['orderby'] ) ? wc_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', 'custom_woocommerce_catalog_orderby' ); | |
add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' ); | |
function custom_woocommerce_catalog_orderby( $sortby ) { | |
$sortby['random_list'] = 'Random'; | |
return $sortby; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment