Created
May 12, 2021 10:39
-
-
Save wbcomdev/da50688e70bad95085cd7326785e5484 to your computer and use it in GitHub Desktop.
This file contains hidden or 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). | |
| */ | |
| function wb_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 ( $orderby_value === 'random_list' ) { | |
| $args['orderby'] = 'rand'; | |
| $args['order'] = ''; | |
| $args['meta_key'] = ''; | |
| } | |
| return $args; | |
| } | |
| add_filter( 'woocommerce_default_catalog_orderby_options', 'wb_custom_woocommerce_catalog_orderby' ); | |
| add_filter( 'woocommerce_catalog_orderby', 'wb_custom_woocommerce_catalog_orderby' ); | |
| /** | |
| * Sorting by custom options. | |
| */ | |
| function wb_custom_woocommerce_catalog_orderby( $sortby ) { | |
| $sortby['random_list'] = 'Random'; | |
| return $sortby; | |
| } | |
| add_filter( 'woocommerce_get_catalog_ordering_args', 'wb_custom_woocommerce_get_catalog_ordering_args' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment