The Code
$(document).ready(function() {
var pickupLabel = "Local Pickup?"; // the text of the label
var buttonArea = $('#cart .cart-buttons'); // where to insert the option
var pickupVariantId = 2882127043; // the variant ID of the local pickup product
Shopify.getCart(function(cart) {
var inCart = false;
$.each(cart.items, function(index, item) {
if (item.variant_id == pickupVariantId) {
inCart = true;
return false;
}
});
buttonArea.append('<div style="text-align: right; margin-top: 15px;"><label for="local-pickup" style="padding: 5px; border: 1px solid #000;"><input id="local-pickup" type="checkbox"' + (inCart ? ' checked' : '') + ' /> ' + pickupLabel + '</label></div>');
});
buttonArea.on('change', '#local-pickup', function() {
if ($(this).is(':checked')) {
Shopify.addItem(pickupVariantId, 1, function(item) {
location.reload();
});
} else {
Shopify.changeItem(pickupVariantId, 0, function(cart) {
location.reload();
});
}
});
});