Created
February 20, 2018 12:16
-
-
Save tiagomatos/948a6213c951e97df116318b01ff0271 to your computer and use it in GitHub Desktop.
Select first variant with stock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
var parentId; | |
var parentOptionCounter = 0; | |
$.each($(".prod-options option"), function( index, option ) { | |
var stock = $(option).data("variant-stock"); | |
if(index == 0 || parentId !== $(option).parent().attr('id')){ | |
parentId = $(option).parent().attr('id'); | |
parentOptionCounter = 0; | |
} | |
if(stock != '0' && parentOptionCounter > 0){ | |
$(option).prop('selected', true).trigger('change'); // selecting the first non-stock zero option. | |
return false; | |
} | |
parentOptionCounter++; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment