';
tableBody.append(rowHTML);
});
/*
* Remove the original X icons
*/
$('.product-remove').remove();
}
/*
* Escape HTML
*/
function escapeHTML(text) {
return $('
')
.text(text)
.html();
}
/*
* Currency
*
* Change ₹ if your WooCommerce
* currency is different.
*/
function wc_price_custom(amount) {
return '$' +
Number(amount).toLocaleString(
'en-US',
{
minimumFractionDigits: 2,
maximumFractionDigits: 2
}
);
}
/*
* ==========================================
* PLUS BUTTON
* ==========================================
*/
$(document).on(
'click',
'.custom-zero-plus',
function () {
let button = $(this);
if (button.prop('disabled')) {
return;
}
let row = button.closest(
'.custom-zero-cart-item'
);
let input = row.find(
'.custom-zero-input'
);
let current =
parseInt(input.val()) || 0;
/*
* First quantity
*/
if (current === 0) {
let productID =
row.attr(
'data-zero-product-id'
);
button.prop('disabled', true);
input.val(1);
/*
* Add to WooCommerce cart
*/
$.ajax({
url: window.CustomCartAjax,
type: 'POST',
data: {
action:
'custom_cart_add_product',
product_id:
productID,
quantity:
1
},
success: function (response) {
if (
response.success
) {
/*
* Reload cart
* so WooCommerce
* handles totals,
* coupons and checkout.
*/
window.location.reload();
}
else {
input.val(0);
button.prop(
'disabled',
false
);
}
},
error: function () {
input.val(0);
button.prop(
'disabled',
false
);
}
});
}
}
);
/*
* ==========================================
* MINUS BUTTON
* ==========================================
*/
$(document).on(
'click',
'.custom-zero-minus',
function () {
let input =
$(this)
.siblings(
'.custom-zero-input'
);
let value =
parseInt(input.val()) || 0;
if (value > 0) {
value--;
}
input.val(value);
}
);
/*
* ==========================================
* INITIAL LOAD
* ==========================================
*/
setTimeout(function () {
addZeroQuantityProducts();
}, 300);
/*
* ==========================================
* WOOCOMMERCE AJAX UPDATE
* ==========================================
*/
$(document.body).on(
'updated_wc_div',
function () {
setTimeout(function () {
addZeroQuantityProducts();
}, 300);
}
);
/*
* ==========================================
* REMOVE X ICON
* ==========================================
*/
$(document).on(
'updated_wc_div',
function () {
$('.product-remove').remove();
}
);
});