Skip to content

Instantly share code, notes, and snippets.

@gterrill
Last active June 22, 2017 00:01
Show Gist options
  • Save gterrill/566663d6dc8c9a22ae5695a16e9519ef to your computer and use it in GitHub Desktop.
Save gterrill/566663d6dc8c9a22ae5695a16e9519ef to your computer and use it in GitHub Desktop.
Hide duration variant option
// ============ Booking Form Snippet =============
{% if product.metafields.bookthatapp.config %}
<div class="booking-form">
<div>
{% capture attribute %}booking-start{% endcapture %}
<label for="{{ attribute }}-{{ product.handle }}">From:</label>
<input id="{{ attribute }}-{{ product.handle }}" type="text" name="properties[From]" size="12" class="datepicker bta required bta-load-enable bta-dp-start" disabled="disabled"
data-handle="{{ product.handle }}" data-variant="{{ product.selected_or_first_available_variant.id }}"
data-bta-product-config="{{ product.metafields.bookthatapp.config }}"
data-bta-variant-config="{% for variant in product.variants %}{{ variant.id }}:{{ variant.metafields.bookthatapp.config }}{% unless forloop.last %},{% endunless %}{% endfor %}"
data-bta-range-partner-id="#booking-finish-{{ product.handle }}"
data-bta-range-days-max="0" data-bta-range-days-min="0" />
</div>
<div>
{% capture attribute %}booking-finish{% endcapture %}
<label for="{{ attribute }}-{{ product.handle }}">To:</label>
<input id="{{ attribute }}-{{ product.handle }}" type="text" name="properties[To]" size="12" class="datepicker bta required bta-load-enable bta-dp-finish" disabled="disabled"
data-bta-range-partner-id="#booking-start-{{ product.handle }}" />
</div>
<div class="bta-validation-messages" style="display:none">
<p class="bta-validation-date-missing">Please select a date</p>
</div>
</div>
<script>
// rental product behaviour
var ProductRental = function() {
_this = this;
this.configs = {};
this.init = function() {
'{{ product.metafields.bookthatapp.config }}'.replace(new RegExp("([^?=&]+)(=([^&]*))?", "g"), function($0, $1, $2, $3) {_this.configs[$1] = $3;});
_this.hideDurationOptionSelect();
};
this.hideDurationOptionSelect = function() {
// hide option for duration (bypass .selector-wrapper inside booking form)
$('.selector-wrapper:nth-child(' + _this.configs['duration_option_position'] + ')').filter(function(index) {
return $(this).parents('.booking-form').length == 0;
}).hide();
};
}
document.addEventListener("DOMContentLoaded", function(event) {
new ProductRental().init();
});
var bta = {
productId: {{ product.id }}
}
</script>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment