Category: Label Rewinders

Showing all 3 results

document.addEventListener('DOMContentLoaded', function () { if (!document.body.classList.contains('single-product')) { return; } document.querySelectorAll('.woocommerce-product-gallery').forEach(function (gallery) { const images = gallery.querySelectorAll('img'); images.forEach(function (img) { if (img.getAttribute('alt') && img.getAttribute('alt').trim() !== '') { return; } // Try to identify the same image elsewhere in the gallery. const largeImage = img.getAttribute('data-large_image'); const src = img.getAttribute('src'); let matchingImage = null; images.forEach(function (other) { if (other === img) { return; } const otherLarge = other.getAttribute('data-large_image'); const otherSrc = other.getAttribute('src'); if ( (largeImage && otherLarge && largeImage === otherLarge) || (src && otherSrc && src === otherSrc) ) { if ( other.getAttribute('alt') && other.getAttribute('alt').trim() !== '' ) { matchingImage = other; } } }); if (matchingImage) { img.setAttribute( 'alt', matchingImage.getAttribute('alt') ); } }); }); });