Created
July 4, 2022 07:41
-
-
Save msulaimanmisri/35625cc330ef2cff0b82bea29b133b45 to your computer and use it in GitHub Desktop.
WordPress WooCommerce Random Product
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 | |
/** | |
* @author Muhamad Sulaiman | |
* @link https://github.com/msulaimanmisri | |
*/ | |
function sm_wc_random_products( $args ) { | |
$orderby_value = isset( $_GET['orderby'] ) ? woocommerce_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; | |
} | |
function sm_wc_random_product_catalog( $sortby ) { | |
$sortby['random_list'] = 'Random'; | |
return $sortby; | |
} | |
add_filter( 'woocommerce_get_catalog_ordering_args', 'sm_wc_random_products' ); | |
add_filter( 'woocommerce_default_catalog_orderby_options', 'sm_wc_random_product_catalog' ); | |
add_filter( 'woocommerce_catalog_orderby', 'sm_wc_random_product_catalog' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment