Shuffle Product Order on Every Visit to Shop Page

This topic has 3 replies, 2 voices, and was last updated 2 days, 19 hours ago ago by khurram virk

  • Avatar: khurram virk
    khurram virk
    Participant
    June 22, 2025 at 10:31

    Dear Sir,

    Good day to you!

    I would like the products on the Shop page to appear in a random order each time a user visits the page, so the same products are not displayed in the same sequence every time.

    Could you please guide me on how to achieve this functionality?

    Here is the link to my shop page:
    ๐Ÿ”— https://askasolution.com/shop/

    Thank you.

    2 Answers
    Avatar: Justin
    Luca Rossi
    Support staff
    June 23, 2025 at 07:57

    Hello @khurram virk,

    Thank you for reaching out to us.

    To display products in a random order on your Shop page each time it is visited, you can achieve this by adding a custom code snippet to your child themeโ€™s functions.php file or by using a custom plugin. Please follow the steps below:

    1. Access your WordPress dashboard.
    2. Navigate to Appearance > Theme File Editor.
    3. Select your child theme and open the functions.php file.
    4. Add the following code at the end of the file:

    
    function custom_random_products_order( $query ) {
        if ( ! is_admin() && is_shop() && $query->is_main_query() ) {
            $query->set( 'orderby', 'rand' );
        }
    }
    add_action( 'pre_get_posts', 'custom_random_products_order', 999 );
    

    5. Save the changes.

    This code will randomize the order of products on your Shop page each time it is loaded.

    Please ensure you are using a child theme before making these changes to avoid losing them during theme updates. If you are not familiar with editing theme files, we recommend consulting with a developer or using a plugin that allows custom code insertion.

    Should you need further assistance, feel free to contact us.

    Best Regards,
    8Themeโ€™s Team

    Avatar: khurram virk
    khurram virk
    Participant
    July 9, 2025 at 11:57

    Thanks for the support! My topic โ€œShuffle Product Order on Every Visit to Shop Pageโ€ has been successfully resolved.

  • Viewing 3 results - 1 through 3 (of 3 total)

The issue related to 'โ€˜Shuffle Product Order on Every Visit to Shop Pageโ€™' has been successfully resolved, and the topic is now closed for further responses

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.