if($('#group_1').length > 0) { var size_group = 1; } else if($('#group_5').length > 0) { var size_group = 5; } else if($('#group_6').length > 0) { var size_group = 6; } var width_group = 4; var color_group = 3; if($('.product-variants-item').length > 0) { $(document).ready(function () { $('body').on('click', 'a.select_size', function () { // if(!$(this).hasClass('disabled')) { var size = $(this).data('id'); $('#group_'+size_group).val(size); $('#group_'+size_group).trigger('change'); // } else { // return false; // } }); $(document).ajaxComplete(function (event, xhr, settings) { checkStocks(); }); function checkStocks() { $('a.select_size').each(function () { var id_attribute = $(this).data('id') + ''; var width_attribute = $('#group_'+width_group).val() + ''; var color_attribute = $('input[name="group['+color_group+']"]:checked').val() + ''; var stock = 0; var q=0; for (var i = 0; i < customsizesstocks.length; i++) { if ($.inArray(width_attribute, customsizesstocks[i]["attributes"]) != -1 && $.inArray(id_attribute, customsizesstocks[i]["attributes"]) != -1 && $.inArray(color_attribute, customsizesstocks[i]["attributes"]) != -1 && parseInt(customsizesstocks[i]['quantity']) > 0) { stock = 1; q = customsizesstocks[i]['quantity']; break; } } if (stock === 1) { $(this).removeClass('disabled'); $(this).attr('title',q+' '+customsizes_in_stock); } else { $(this).addClass('disabled'); $(this).attr('title',customsizes_out_of_stock); } }); } checkStocks(); $('body').on('click', 'a.select_size', function () { return false; }); }); }