-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwine-shop-minimum-order-ajax.js
34 lines (32 loc) · 1.22 KB
/
wine-shop-minimum-order-ajax.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
jQuery(function ($) {
// Function to handle the cart update.
function update_cart() {
$.ajax({
type: 'POST',
url: wine_shop_minimum_order_ajax_object.ajax_url,
data: {
action: 'wine_shop_minimum_order_update_cart',
},
dataType: 'json',
success: function (response) {
if (response.success) {
$('.woocommerce-error, .woocommerce-message').remove();
$('.woocommerce').prepend('<div class="woocommerce-message" role="alert">' + response.message + '</div>');
} else {
$('.woocommerce-error, .woocommerce-message').remove();
$('.woocommerce').prepend('<div class="woocommerce-error" role="alert">' + response.message + '</div>');
}
},
});
}
// Update the cart when the quantity is changed.
$('body').on('change', 'input.qty', function () {
update_cart();
});
// Update the cart when an item is removed.
$('body').on('click', 'a.remove', function () {
$(document.body).on('wc_fragments_refreshed', function () {
update_cart();
});
});
});