Open product detail page when product page has only one product

Description: If product category/shop page has 1 product only >> When users access shop/product category page >> browser will open product detail page.

You can use this code to Code Injection > Footer

<script>
window.addEventListener('DOMContentLoaded', function() {
  const productItems = document.querySelectorAll('.grid-item');
  
  if (productItems.length === 1) {
    const productLink = productItems[0].querySelector('.grid-item-link');
    if (productLink) {
      window.location.href = productLink.getAttribute('href');
    }
  }
});
</script>

1 Like