Auto select product size

This commit is contained in:
Roman Pyrih
2025-09-19 14:28:11 +02:00
parent 1267056c07
commit 0c7ea5139b
4 changed files with 101 additions and 56 deletions

View File

@@ -1146,3 +1146,37 @@ $(document).ready(function () {
$widget.find('.preloader').fadeOut(500)
}, 10000)
})
$(document).ready(function () {
$('body').on(
'click',
'#box-product-accessories .buy-protector-btn',
function (e) {
let selectedSize = $(
'#add-to-cart-or-refresh .product-variants .product-variants-item select#group_3 option:selected'
)
.text()
.trim()
localStorage.removeItem('selectedSize')
localStorage.setItem('selectedSize', JSON.stringify(selectedSize))
}
)
if (localStorage.getItem('selectedSize')) {
let savedSize = JSON.parse(localStorage.getItem('selectedSize'))
let $select = $(
'#add-to-cart-or-refresh .product-variants .product-variants-item select#group_3'
)
$select.find('option').each(function () {
if ($(this).text().trim() === savedSize) {
$(this).prop('selected', true).trigger('change')
return false
}
})
localStorage.removeItem('selectedSize')
}
})