"Select" custom above, default below. White and P are out of stock.
I found that the WooCommerce JS Variations removes options out of stock programmatically, but as my script runs after the WooCommerce script I thought it should work. I even managed to make it work by adding a 2000ms setTimeout, but it's too long and actually breaks other functions I have. I'll be grateful if anyone knows how to solve this.
$('.variations select').each(function(){
var select = $(this);
var div = $('<div class="grupo-atributos">');
var ul = $('<ul>');
select.parent('.value').siblings('.label').find('label').each(function(){
var label = $(this).text();
div.append('<span>'+label+'</span>');
});
$('#custom-select-produto-variavel').append(div);
div.append(ul);
select.find('option').each(function(){
var titulo = $(this).text();
var data_value = $(this).val();
ul.append('<li data-value='+data_value+'>'+titulo+'</li>');
select.change(function(){
select.find('option:selected').each(function(){
var opcao_selected = $(this);
select.find('option:not(:selected)').each(function(){
var opcao_not_selected = $(this);
$('#custom-select-produto-variavel li').each(function(){
var opcao_custom = $(this);
if(opcao_custom.attr('data-value')==opcao_selected.val())
opcao_custom.addClass('atributo-selected');
if(opcao_custom.attr('data-value')==opcao_not_selected.val())
opcao_custom.removeClass('atributo-selected');
});
});
});
}).change();
});
});
$('#custom-select-produto-variavel div ul li:contains("Escolha uma opção")').remove();
$('#custom-select-produto-variavel ul li').click(function() {
var novoVal = $(this).data('value');
$('.variations select:has([value='+novoVal+'])').val(novoVal);
$('.variations select').trigger('change');
});
<div id="custom-select-produto-variavel"></div>