• Resolved Deepak

    (@d88pak)


    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)
  • Afzal (woo-hc)

    (@afzalpansuvi)

    Hi Deepak,

    Thank you for reaching out to us with your question. It’s great to see that you’ve already managed to add a random sorting option to your shop page!

    To add a similar option to the Product List Widget, you would need to modify the widget’s code. However, please note that writing or providing custom code is not within the scope of our support policy. For development and custom coding questions, it’s best to ask for insight related to those on either the WooCommerce Advanced Facebook group or the WooCommerce Community Slack. You can also seek help from the following:

    I wish I could help more, but hopefully, this gets you going in the right direction to get the job done.

Viewing 1 replies (of 1 total)
  • The topic ‘How to Add “Random” option on Product List Widget’ is closed to new replies.