Randomize items in shop

The following bit of code randomizes product order in the main shop category which displays all products. Very straight forward and easy to implement. Only Javascript is required.

HTML:
JAVASCRIPT:

document.addEventListener('DOMContentLoaded', function() {
var getURL = window.location.href;
const subString = 'shop';
const badString = 'shop/'; 
const badStringTwo = 'sanctum';
if (getURL.includes(badString) || getURL.includes(badStringTwo)){ 
}
else if (getURL.includes(subString)) { 
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]);
		}
	}
}
else { }
});
CSS:

Previous
Previous

Removing prefixes (select, from, comma)

Next
Next

Sticky cart icon for mobile