Kaffeerösterei · Beanatic Coffee Roasters · Schweizer Specialty Coffee Espresso-Manufaktur in Hägglingen Kanton Aargau
').html(message);
var $items = $temp.find('li');
if ($items.length > 0) {
$items.each(function() {
var txt = $(this).text();
var translated = txt
.replace('Please fill in the required fields', 'Bitte fülle alle markierten Pflichtfelder aus')
.replace('Ungültige Bezahlmethode', 'Bitte Zahlungsmethode auswählen')
.replace('Invalid payment method', 'Bitte Zahlungsmethode auswählen')
.replace('Billing First name', 'Vorname')
.replace('Billing Last name', 'Nachname')
.replace('is a required field', 'ist ein Pflichtfeld')
.replace('is not a valid email address', 'ist keine gültige E-Mail');
errorList += '' + translated + ' ';
});
} else {
errorList = '' + $temp.text() + ' ';
}
$.magnificPopup.open({
items: {
src: '
' +
'
'
},
type: 'inline',
mainClass: 'agb-lightbox-wrapper dark-overlay',
fixedContentPos: false,
callbacks: {
open: function() {
$('input[name="coupon_code"], #coupon_code').val('').blur();
$(document).off('click', '.error-close-btn').on('click', '.error-close-btn', function() { $.magnificPopup.close(); });
},
afterClose: function() { $('.woocommerce-error').remove(); }
}
});
}
/* --- 3. LIVE VALIDIERUNG E-MAIL --- */
function validateEmailMatch() {
var email1 = $('#billing_email').val();
var email2 = $('#billing_email_check').val();
var $field1 = $('#billing_email_field');
var $field2 = $('#billing_email_check_field');
var errorMsg = 'E-Mail-Adressen stimmen nicht überein';
$('.beanatic-email-error').remove();
if (email1 !== "" && email2 !== "" && email1 !== email2) {
$field1.addClass('woocommerce-invalid'); $field2.addClass('woocommerce-invalid');
$field1.append(errorMsg); $field2.append(errorMsg);
} else if (email1 === email2 && email1 !== "") {
$field1.removeClass('woocommerce-invalid'); $field2.removeClass('woocommerce-invalid');
}
}
/* --- 4. EVENT TRIGGER --- */
$(document.body).on('checkout_error', function(event, error_message) {
$('html, body').stop();
$('form.checkout').addClass('beanatic-show-errors');
if ($('input[name="payment_method"]:checked').length === 0) { $('#payment').addClass('woocommerce-invalid'); }
showBeanaticErrorPopup(error_message);
});
$(document).ajaxComplete(function(event, xhr, settings) {
if (settings.url.indexOf('wc-ajax=apply_coupon') !== -1) {
setTimeout(function() {
var $errorBox = $('.woocommerce-error').first();
if ($errorBox.length > 0) { showBeanaticErrorPopup($errorBox.html()); }
else { $('input[name="coupon_code"], #coupon_code').val('').blur(); }
}, 50);
}
});
$(document).ready(function() {
initSavoyLightboxLinks();
$(document.body).on('updated_checkout updated_shipping_method', function() { initSavoyLightboxLinks(); });
$(document).on('blur change', '#billing_email, #billing_email_check', function() { validateEmailMatch(); });
/* --- 5. PERSISTENZ & LOGIN/LOGOUT-RESET (E-MAIL FIX) --- */
if ($('body').hasClass('woocommerce-checkout')) {
var sessionKey = 'beanatic_checkout_data';
var isLoggedIn = $('body').hasClass('logged-in');
if (isLoggedIn) {
// RESET NACH LOGIN
if (!sessionStorage.getItem('beanatic_status_logged_in')) {
sessionStorage.removeItem(sessionKey);
sessionStorage.removeItem('beanatic_payment_method');
sessionStorage.removeItem('chosenPaymentMethod');
// WICHTIG: Wir holen uns die E-Mail vom aktuellen Profil, falls das Feld leer bleibt
// WooCommerce füllt es oft verzögert. Wir setzen es hier fest.
var userEmail = '';
if (userEmail !== "") {
$('#billing_email, #billing_email_check').val(userEmail);
}
sessionStorage.setItem('beanatic_status_logged_in', 'true');
}
} else {
// RESET NACH LOGOUT
if (sessionStorage.getItem('beanatic_status_logged_in')) {
sessionStorage.removeItem(sessionKey);
sessionStorage.removeItem('beanatic_payment_method');
sessionStorage.removeItem('chosenPaymentMethod');
$('#billing_email, #billing_email_check').val('');
sessionStorage.removeItem('beanatic_status_logged_in');
}
}
if (!sessionStorage.getItem('beanatic_checkout_active')) {
$('.woocommerce-billing-fields input, .woocommerce-shipping-fields input').val('');
sessionStorage.removeItem(sessionKey); sessionStorage.removeItem('beanatic_payment_method');
sessionStorage.setItem('beanatic_checkout_active', 'true');
} else {
var savedData = JSON.parse(sessionStorage.getItem(sessionKey) || '{}');
$.each(savedData, function(name, value) { if(value !== "") { $('[name="' + name + '"]').val(value); } });
var savedMethod = sessionStorage.getItem('beanatic_payment_method');
if (savedMethod) { $('input[name="payment_method"][value="' + savedMethod + '"]').prop('checked', true).change(); }
}
$(document).on('input change', '.woocommerce-billing-fields input, .woocommerce-shipping-fields input', function() {
var savedData = JSON.parse(sessionStorage.getItem(sessionKey) || '{}');
savedData[$(this).attr('name')] = $(this).val();
sessionStorage.setItem(sessionKey, JSON.stringify(savedData));
});
$(document).on('change', 'input[name="payment_method"]', function() {
$('#payment').removeClass('woocommerce-invalid');
sessionStorage.setItem('beanatic_payment_method', $(this).val());
});
}
});
})(jQuery);
Hinweis
' + '' +
'
' +
'' +
'Bitte korrigiere folgende Angaben:
' + '- ' + errorList + '
Updating…