Created
September 25, 2018 11:06
-
-
Save yasaryousuf/9123e8db589100ce9fad169ff9861ce2 to your computer and use it in GitHub Desktop.
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
individualPriceChange(); | |
totalPriceChange(); | |
$(".qty").change(function() { | |
individualPriceChange(); | |
totalPriceChange(); | |
}); | |
// price calculation row | |
function individualPriceChange() { | |
$('.itemrow').each(function() { | |
var price = $(this).find('.price').val(); | |
var quantity = $(this).find('.qty').val(); | |
var total = price * quantity; | |
$(this).find('.total').val(total); | |
}); | |
} | |
// price calculation total | |
function totalPriceChange() { | |
var price = 0; | |
$('[name="individual_total_price"]').each(function() { | |
price += parseFloat($(this).val()); | |
$(this).parents("tbody").find('.total_price').val(price); | |
}); | |
} | |
// item select | |
$(document).on("click", ".item_select_button", function() { | |
qty = $(this).parents(".col-md-4").find(".item_quantity").val(); | |
if (!qty || qty == 0) { | |
alert("Item quantity can't be Zero"); | |
$(this).prop('checked', false); | |
} else { | |
var selected_items = []; | |
$('.item_select_button:checkbox:checked').each(function() { | |
item_id = $(this).parents(".col-md-4").find(".item_id").val(); | |
qty = $(this).parents(".col-md-4").find(".item_quantity").val(); | |
selected_items.push({ | |
"id": item_id, | |
"qty": qty | |
}); | |
}); | |
$.ajax({ | |
type: 'POST', | |
url: "/wp-admin/admin-ajax.php?action=save_customer_item", | |
data: { | |
action: 'save_customer_item', | |
selected_items: selected_items, | |
}, | |
}) | |
.done(function(response) { | |
}) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment