Auto select product size
This commit is contained in:
@@ -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')
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user