Created
January 13, 2017 18:11
-
-
Save gterrill/956dd5b6c45f57f1c886de52a1cd21d2 to your computer and use it in GitHub Desktop.
Restrict availability when variant option being used for number of attendees
This file contains 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
<script> | |
$('form[action="/cart/add"]').on('bta.datetimeChange', function(event, form) { | |
// restrict number of attendees dropdown to only allow available number of seats | |
var qtySelector = $('.single-option-selector:first'), | |
max = form.getAvailability(), | |
currentQty = parseInt(qtySelector.val(), 10); | |
qtySelector.find('option').removeAttr('disabled'); | |
qtySelector.find('option').filter(function () { | |
return parseInt(this.value, 10) > max; | |
}).prop('disabled', true); | |
qtySelector.css('border-color', ''); | |
$('#attendees-updated').remove(); | |
if (currentQty > max) { | |
var maxAvailable = qtySelector.find('option').not(':disabled').last().val(); | |
if (maxAvailable) { | |
qtySelector.val(maxAvailable); | |
qtySelector.css('border-color', 'red'); | |
qtySelector.parents('.selector-wrapper').append('<p id="attendees-updated"><small><b>Note:</b> Number of spots updated based on availability</small></p>'); | |
} | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment