You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
164 lines
7.0 KiB
164 lines
7.0 KiB
jQuery(document).ready(function($) {
|
|
jQuery(document.body).on('updated_checkout', function() {
|
|
// Найти новые методы доставки внутри shop_table
|
|
var shippingMethodsHtml = jQuery('.woocommerce-checkout-review-order-table .woocommerce-shipping-methods').html();
|
|
// Обновить кастомный блок
|
|
if(!shippingMethodsHtml){
|
|
shippingMethodsHtml ='<p>Не удалось получить доступные методы доставки! <br>Укажите свой город для получения доступных методов.</p>'
|
|
}
|
|
jQuery('#custom-shipping-methods').html(shippingMethodsHtml);
|
|
jQuery('.order-contacts__delivery').removeClass('loading');
|
|
|
|
jQuery('.modal-map-control__item.active').click()
|
|
});
|
|
|
|
|
|
$(document.body).on('update_checkout', function() {
|
|
jQuery('.order-contacts__delivery').addClass('loading');
|
|
});
|
|
|
|
$('body').on('click', '.modal-map-control__item', function(){
|
|
if (!$(this).hasClass('active')){
|
|
$('#addr_inp').val('')
|
|
$('#pvz_inp').val('')
|
|
$('#billing_address_1').val('')
|
|
$('#billing_address_2').val('')
|
|
}
|
|
$('.shipping-add-info').removeClass('active')
|
|
var remote = $(this).data('remote')
|
|
$('.shipping-add-info[data-remote="' + remote + '"]').addClass('active')
|
|
})
|
|
|
|
jQuery('#addr_inp').on('click', function(){
|
|
jQuery('#address_input').addClass('active')
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery(document).ready(function($) {
|
|
// Перехват отправки формы купона
|
|
$(document).on('click', 'button[name="apply_coupon"]', function(e) {
|
|
e.preventDefault(); // Останавливаем отправку основной формы
|
|
|
|
// Отправка данных купона через AJAX
|
|
var couponCode = $('#coupon_code').val();
|
|
|
|
if (!couponCode) {
|
|
alert('Пожалуйста, введите код купона.');
|
|
return;
|
|
}
|
|
|
|
$.ajax({
|
|
url: wc_checkout_params.ajax_url, // URL для AJAX-запроса WooCommerce
|
|
type: 'POST',
|
|
data: {
|
|
action: 'apply_coupon',
|
|
coupon_code: couponCode
|
|
},
|
|
success: function(response) {
|
|
if (response.success) {
|
|
$(document.body).trigger('update_checkout');
|
|
$('#promo_form').hide()
|
|
$('#promo_delete').show()
|
|
$('#promo_err').hide()
|
|
$('#coupon_code_app').val('Применен промокод: ' + couponCode)
|
|
$('#delete_coupon').data('coupon', couponCode)
|
|
} else {
|
|
$('#promo_err').show()
|
|
}
|
|
},
|
|
error: function() {
|
|
alert('Произошла ошибка. Попробуйте ещё раз.');
|
|
}
|
|
});
|
|
});
|
|
|
|
jQuery('#pvz_inp').on('click', function(){
|
|
jQuery('.open-pvz-btn').click()
|
|
})
|
|
|
|
$('#address_input input').on('change, input, keyup', function(){
|
|
var address = $('#f_address').val()
|
|
var apart = $('#f_apartment').val()
|
|
var floor = $('#f_floor').val()
|
|
var entrance = $('#f_entrance').val()
|
|
var number_phone = $('#f_number-phone').val()
|
|
|
|
var address_2 = ''
|
|
|
|
if (apart){
|
|
address_2 += ' кв ' + apart
|
|
}
|
|
if (floor){
|
|
address_2 += ' этаж ' + floor
|
|
}
|
|
if (entrance){
|
|
address_2 += ' подъезд ' + entrance
|
|
}
|
|
if (number_phone){
|
|
address_2 += ' домофон ' + number_phone
|
|
}
|
|
$('#addr_inp').val(address + address_2)
|
|
$('#billing_address_1').val(address)
|
|
$('#billing_address_2').val(address_2)
|
|
})
|
|
});
|
|
|
|
|
|
jQuery(document).ready(function ($) {
|
|
$(document.body).on('checkout_error', function () {
|
|
// $('.woocommerce-error').remove();
|
|
$('.form-input__error').removeClass('active');
|
|
|
|
// // Добавляем ошибки рядом с полями
|
|
$('.woocommerce-error li').each(function () {
|
|
var errorMessage = $(this).text().trim();
|
|
var fieldKey = $(this).data('id'); // Предполагается, что ошибка содержит data-id
|
|
console.log(errorMessage)
|
|
console.log(fieldKey)
|
|
if (fieldKey) {
|
|
var errorContainer = $('#' + fieldKey + '-error');
|
|
if (errorContainer.length) {
|
|
errorContainer.html('<span class="error-message">' + errorMessage + '</span>');
|
|
$('#' + fieldKey + '-error').addClass('active');
|
|
}
|
|
}
|
|
if (errorMessage == 'phone_err' || errorMessage == 'The string supplied did not seem to be a phone number.' || errorMessage.includes('Некорректный номер телефона')){
|
|
$('#billing_phone-error').html('Неправильно введен номер')
|
|
$('#billing_phone-error').addClass('active');
|
|
}
|
|
if (errorMessage == 'Order pickup point not selected.' || errorMessage == 'Не выбран ПВЗ для доставки заказа.'){
|
|
$('#pvz-error').html('Не выбран ПВЗ для доставки заказа.')
|
|
$('#pvz-error').addClass('active');
|
|
}
|
|
if (errorMessage == 'adress_error'){
|
|
$('#adr-error').html('Не указан адрес доставки')
|
|
$('#adr-error').addClass('active');
|
|
}
|
|
if (errorMessage == 'Неверный адрес эл. почты для выставления счета'){
|
|
$('#billing_email-error').html(errorMessage).addClass('active');
|
|
}
|
|
if(errorMessage == 'Не выбран метод доставки. Пожалуйста перепроверьте ваш адрес или обратитесь за помощью к администрации сайта.'){
|
|
$('#billing_city-error').html(errorMessage).addClass('active');
|
|
}
|
|
if(errorMessage == 'Этот email уже зарегистрирован.'){
|
|
$('#acc-error').html('Этот email уже зарегистрирован. Войдите в свой аккаунт или укажите другой E-mail.').addClass('active');
|
|
}
|
|
});
|
|
});
|
|
|
|
$('#delete_coupon').on('click', function(){
|
|
$('.woocommerce-remove-coupon[data-coupon=' + $(this).data('coupon') + ']').click()
|
|
$('#promo_form').show()
|
|
$('#promo_delete').hide()
|
|
})
|
|
$('.woocommerce-remove-coupon').on('click', function(){
|
|
$('#promo_form').show()
|
|
$('#promo_delete').hide()
|
|
})
|
|
});
|
|
|
|
|
|
|
|
|