Jump to content

SS 7.1 - Is there a way to randomize the order of store products on each load?

Go to solution Solved by Beyondspace,

Recommended Posts

3 hours ago, alanx said:

I assume you'd need some sorta javascript code to achieve this. If anyone knows the right code, please let me know. Thank you.

what is your site url

Greeting, it's BeyondSpace, I am Squarespace dev focus on provide solutions to enhance feature that squarespace.com can't provide.
Feel free to check my current Squarespace Plugins Developement: Enable Pinch/Zoom on lightbox, Delivery Date Picker, Keyword Highlighter
If you find my answer fit your need, let's leave a like or upvote so others with the same issue can find their solution. Thank you

Link to comment
1 minute ago, alanx said:

try

document.addEventListener('DOMContentLoaded', function() {
    const productGrid = document.querySelector('.products-flex-container .list-grid');
    if (productGrid) {
        var productItems = productGrid.querySelectorAll('.grid-item');
        for (var i = productItems.length; i >= 0; i--) {
            productGrid.appendChild(productItems[Math.random() * i | 0]);
        }
    }
});

 

Greeting, it's BeyondSpace, I am Squarespace dev focus on provide solutions to enhance feature that squarespace.com can't provide.
Feel free to check my current Squarespace Plugins Developement: Enable Pinch/Zoom on lightbox, Delivery Date Picker, Keyword Highlighter
If you find my answer fit your need, let's leave a like or upvote so others with the same issue can find their solution. Thank you

Link to comment
  • Solution
1 minute ago, alanx said:

 

Should I insert this code in Advanced > Code Injection > Header? And are there any opening and closing tags? I'm sorry, I'm a little clueless when it comes to JS code.

add to footer

<script>
document.addEventListener('DOMContentLoaded', function() {
    const productGrid = document.querySelector('.products-flex-container .list-grid');
    if (productGrid) {
        var productItems = productGrid.querySelectorAll('.grid-item');
        for (var i = productItems.length; i >= 0; i--) {
            productGrid.appendChild(productItems[Math.random() * i | 0]);
        }
    }
});
</script>

 

Greeting, it's BeyondSpace, I am Squarespace dev focus on provide solutions to enhance feature that squarespace.com can't provide.
Feel free to check my current Squarespace Plugins Developement: Enable Pinch/Zoom on lightbox, Delivery Date Picker, Keyword Highlighter
If you find my answer fit your need, let's leave a like or upvote so others with the same issue can find their solution. Thank you

Link to comment
  • 1 year later...
22 hours ago, tcrown86 said:

are you able to help me out as well please

https://adventuresofrico.com/store

Thanks

Rico

 

Try changing his code to this

<script>
document.addEventListener('DOMContentLoaded', function() {
    const productGrid = document.querySelector('.ProductList-grid');
    if (productGrid) {
        var productItems = productGrid.querySelectorAll('.ProductList-item');
        for (var i = productItems.length; i >= 0; i--) {
            productGrid.appendChild(productItems[Math.random() * i | 0]);
        }
    }
});
</script>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

How to: Setup Password & Share url Insert Custom CSS - Page Header - Upload Custom Font - Upload File - Find Block ID - Contact Customer Care

Link to comment
7 hours ago, tuanphan said:

Try changing his code to this

<script>
document.addEventListener('DOMContentLoaded', function() {
    const productGrid = document.querySelector('.ProductList-grid');
    if (productGrid) {
        var productItems = productGrid.querySelectorAll('.ProductList-item');
        for (var i = productItems.length; i >= 0; i--) {
            productGrid.appendChild(productItems[Math.random() * i | 0]);
        }
    }
});
</script>

 

thanks soooo much, worked well. have a great weekend.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.