How to Add “Random” option on Product List Widget
-
Hi,
I need to show the products (featured/on sale/latest) in random order. By default it only has ASC or DESC options only. How can I add an option to choose Random for this widget?
I checked the page https://woo.com/document/woocommerce-widgets/ but no clue.
for the shop page, I was able to add the random option with this code
// Add "Random Products" option for shop page (Apperance > Customize > WooCommerce) add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woo_catalog_ordering_args' ); function custom_woo_catalog_ordering_args( $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; } add_filter( 'woocommerce_default_catalog_orderby_options', 'woocommerce_catalog_random_orderby' ); add_filter( 'woocommerce_catalog_orderby', 'woocommerce_catalog_random_orderby' ); function woocommerce_catalog_random_orderby( $sortby ) { $sortby['random_list'] = 'Random'; return $sortby; }
How can add the similar option on Product list Widget?
Thanks!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How to Add “Random” option on Product List Widget’ is closed to new replies.