Skip to content

Instantly share code, notes, and snippets.

@essmahr
Created February 5, 2018 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save essmahr/8853a155490b1ece3ff1fbe9a032132b to your computer and use it in GitHub Desktop.
Save essmahr/8853a155490b1ece3ff1fbe9a032132b to your computer and use it in GitHub Desktop.
Quantity field:
After {{ item.variant.id }} and value="{{ item.quantity }}", add the following:
{% unless item.variant.inventory_management == blank or item.variant.inventory_policy == 'continue' %} max="{{ item.variant.inventory_quantity }}" {% endunless %}
At the end of cart.liquid, add
<script>
jQuery('[max]').change(function() {
var max = parseInt(jQuery(this).attr('max'), 10);
if (isNaN(max)) {
return
}
var value = parseInt(jQuery(this).val(), 10) || 0;
if (value > max) { jQuery(this).val(max); }
});
/* change won't trigger on initial load */
jQuery('[max]').each(function() {
var max = parseInt(jQuery(this).attr('max'), 10);
if (isNaN(max)) {
return
}
var value = parseInt(jQuery(this).val(), 10) || 0;
if (value > max) { jQuery(this).val(max); }
});
if (typeof BuyXSubmit == "function") {
var buyx_checkout_selectors = ["input[name='checkout']", "button[name='checkout']", "input[name='goto_pp']", "button[name='goto_pp']", "input[name='goto_gc']", "button[name='goto_gc']", "[href$='checkout']", ".google-wallet-button-holder", ".amazon-payments-pay-button"];
window.buyx_cart_global = {{ cart | json }}
buyx_checkout_selectors.forEach(function(selector) {
jQuery(selector).bind("click", function() {
console.log("click")
return BuyXSubmit(window.buyx_cart_global, "updates_{key}");
//use appropriate selector for your theme, e.g. "input[data-id={variant_id}]"
})
});
}
</script>
<style>
.buyx-msg {
color: #F45B4F;
font-weight: bold;
font-size: 18px;
width: 100%;
text-align: center;
margin-bottom: 10px;
}
/*
.buyx-msg a {
color: #000000;
text-decoration: underline;
}
*/
.buyx-msg:empty {
display: none;
}
</style>
If the cart doesn't have an Update button, add it with
<input type="submit" id="update-cart" class="btn" name="update" value="Update Cart" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment