WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
Woocommerce Featured Products widget (4 posts)

  1. peer_012
    Member
    Posted 1 year ago #

    I recently edited Woocommerce's Products On-Sale widget making it display random products marked on-sale by changing the line 'orderby' => 'date', to 'orderby' => 'rand',. Now I want to edit the Featured Products widget to do the same. However, I can't seem to get it to work. I have changed to the code to:

    $query_args['meta_query'][] = array(
    'key' => '_featured',
    'value' => 'yes',
    'orderby' => 'rand'
    );

    but it still does not display random products marked featured. Can anyone please help me out. Thanks in advance!

    http://wordpress.org/extend/plugins/woocommerce/

  2. jameskoster
    Member
    Plugin Author

    Posted 1 year ago #

    That's because you're modifying the _meta query_.

    In 2.1 you can order the products randomly.

  3. r3plicant3
    Member
    Posted 1 year ago #

    I changed the line 84 and worked fine:

    <?php $query_args = array('posts_per_page' => $number, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'orderby' => 'rand');

  4. addesigns
    Member
    Posted 5 months ago #

    Just in case anyone stumbles upon b/c they wish to change the Products On-Sale widget to random like I did, here is the file you must edit:

    woocommerce/classes/widgets/class-wc-widget-onsale.php

    Search for orderby like peer_012 stated and change 'date' to 'rand'

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic