$(function() {
$('#billing_postcode').change(function() { // $('#place_order').mouseover(function() {
var quantity = parseInt($('.shop_table .cart_item .product-name .product-quantity').text().match(/(\d+)/)[0]); var courierDpdFood = $('#shipping_method_0_flexible_shipping_single7').val(); //flexible_shipping_single:7 var courierDpdClassic = $('#shipping_method_0_flexible_shipping_single9').val(); //flexible_shipping_single:9
setTimeout(function() { if (courierDpdFood) { var rest = Math.abs((quantity % 4) - 4); if (rest != 4) { fireSweet(rest); } } else if (courierDpdClassic) { var rest = Math.abs((quantity % 3) - 3); if (rest != 3) {
fireSweet(rest); } } }, 3000)
}); })
function fireSweet(rest) {
Swal.fire({ icon: 'info', title: 'Jeszcze jedno...', text: "Uprzejmie informujemy, iż możesz dodać do koszyka jeszcze "+ rest + " " + polishPlural("kurczaka", "kurczaki", "kurczaków", rest) + " i wciąż zachować tą samą kwotę dostawy. Jeżeli nie masz możliwości zamrożenia kolejnego kurczaka podaruj go swoim znajomym. Oni też zasługują na to żeby się zdrowo odżywiać.", confirmButtonText: "Dodaję kurczaka", showCancelButton: true, cancelButtonText: "Nie, dziękuję",
}).then((result) => { if (result.value) { window.location.href = `/koszyk` } });
}
function polishPlural(singularNominativ, pluralNominativ, pluralGenitive, value) { if (value === 1) { return singularNominativ; } else if (value % 10 >= 2 && value % 10 <= 4 && (value % 100 < 10 || value % 100 >= 20)) { return pluralNominativ; } else { return pluralGenitive; } }