@ -1,42 +1,75 @@
jQuery ( document ) . ready ( function ( $ ) {
jQuery ( document ) . ready ( function ( $ ) {
// Static translations for both English and Russian
var translations = {
en : {
error _coupon _empty : 'Please enter the coupon code.' ,
error _coupon _invalid : 'Error! The coupon code is invalid or does not exist.' ,
error _generic : 'An error occurred. Please try again.' ,
shipping _method _error : 'No pickup point selected for delivery.' ,
shipping _address _error : 'Delivery address not provided' ,
email _taken _error : 'This email is already registered. Please log in or provide a different email.' ,
phone _number _error : 'Incorrect phone number entered.' ,
shipping _method _missing : 'No delivery method selected. Please check your address or contact the site administration for help.' ,
change _address : 'Change address' ,
shipping _updated : 'Shipping methods will be updated during checkout.' ,
coupon _applied : 'Coupon applied: '
} ,
ru : {
error _coupon _empty : 'Пожалуйста, введите код купона.' ,
error _coupon _invalid : 'Ошибка! Промокод введен неверно или не существует.' ,
error _generic : 'Произошла ошибка. Попробуйте ещё раз.' ,
shipping _method _error : 'Не выбран ПВЗ для доставки заказа.' ,
shipping _address _error : 'Не указан адрес доставки' ,
email _taken _error : 'Этот email уже зарегистрирован. Войдите в свой аккаунт или укажите другой E-mail.' ,
phone _number _error : 'Неправильно введен номер' ,
shipping _method _missing : 'Не выбран метод доставки. Пожалуйста перепроверьте ваш адрес или обратитесь за помощью к администрации сайта.' ,
change _address : 'Изменить адрес' ,
shipping _updated : 'Методы доставки будут обновлены в процессе оформления заказа.' ,
coupon _applied : 'Применен промокод: '
}
} ;
// Get the current language (assuming you're using a data-lang attribute on the body or html tag)
var currentLang = $ ( 'body' ) . data ( 'lang' ) || 'en' ; // Default to 'en' if no lang attribute is found
// Use the correct translations based on the current language
var currentTranslations = translations [ currentLang ] ;
jQuery ( document . body ) . on ( 'updated_checkout' , function ( ) {
jQuery ( document . body ) . on ( 'updated_checkout' , function ( ) {
// Найти новые методы доставки внутри shop_table
// Найти новые методы доставки внутри shop_table
var shippingMethodsHtml = jQuery ( '.woocommerce-checkout-review-order-table .woocommerce-shipping-methods' ) . html ( ) ;
var shippingMethodsHtml = jQuery ( '.woocommerce-checkout-review-order-table .woocommerce-shipping-methods' ) . html ( ) ;
// Обновить кастомный блок
// Обновить кастомный блок
if ( ! shippingMethodsHtml ) {
if ( ! shippingMethodsHtml ) {
shippingMethodsHtml = '<p>Не удалось получить доступные методы доставки! <br>Укажите свой город для получения доступных методов.</p>'
shippingMethodsHtml = '<p>' + currentTranslations . shipping _method _missing + '</p>' ;
}
}
jQuery ( '#custom-shipping-methods' ) . html ( shippingMethodsHtml ) ;
jQuery ( '#custom-shipping-methods' ) . html ( shippingMethodsHtml ) ;
jQuery ( '.order-contacts__delivery' ) . removeClass ( 'loading' ) ;
jQuery ( '.order-contacts__delivery' ) . removeClass ( 'loading' ) ;
jQuery ( '.modal-map-control__item.active' ) . click ( )
jQuery ( '.modal-map-control__item.active' ) . click ( ) ;
} ) ;
} ) ;
$ ( document . body ) . on ( 'update_checkout' , function ( ) {
$ ( document . body ) . on ( 'update_checkout' , function ( ) {
jQuery ( '.order-contacts__delivery' ) . addClass ( 'loading' ) ;
jQuery ( '.order-contacts__delivery' ) . addClass ( 'loading' ) ;
} ) ;
} ) ;
$ ( 'body' ) . on ( 'click' , '.modal-map-control__item' , function ( ) {
$ ( 'body' ) . on ( 'click' , '.modal-map-control__item' , function ( ) {
if ( ! $ ( this ) . hasClass ( 'active' ) ) {
if ( ! $ ( this ) . hasClass ( 'active' ) ) {
$ ( '#addr_inp' ) . val ( '' )
$ ( '#addr_inp' ) . val ( '' ) ;
$ ( '#pvz_inp' ) . val ( '' )
$ ( '#pvz_inp' ) . val ( '' ) ;
$ ( '#billing_address_1' ) . val ( '' )
$ ( '#billing_address_1' ) . val ( '' ) ;
$ ( '#billing_address_2' ) . val ( '' )
$ ( '#billing_address_2' ) . val ( '' ) ;
}
}
$ ( '.shipping-add-info' ) . removeClass ( 'active' )
$ ( '.shipping-add-info' ) . removeClass ( 'active' ) ;
var remote = $ ( this ) . data ( 'remote' )
var remote = $ ( this ) . data ( 'remote' ) ;
$ ( '.shipping-add-info[data-remote="' + remote + '"]' ) . addClass ( 'active' )
$ ( '.shipping-add-info[data-remote="' + remote + '"]' ) . addClass ( 'active' ) ;
} )
} ) ;
jQuery ( '#addr_inp' ) . on ( 'click' , function ( ) {
jQuery ( '#addr_inp' ) . on ( 'click' , function ( ) {
jQuery ( '#address_input' ) . addClass ( 'active' )
jQuery ( '#address_input' ) . addClass ( 'active' ) ;
} )
} ) ;
} ) ;
} ) ;
jQuery ( document ) . ready ( function ( $ ) {
jQuery ( document ) . ready ( function ( $ ) {
// Перехват отправки формы купона
// Перехват отправки формы купона
$ ( document ) . on ( 'click' , 'button[name="apply_coupon"]' , function ( e ) {
$ ( document ) . on ( 'click' , 'button[name="apply_coupon"]' , function ( e ) {
@ -46,7 +79,7 @@ jQuery(document).ready(function($) {
var couponCode = $ ( '#coupon_code' ) . val ( ) ;
var couponCode = $ ( '#coupon_code' ) . val ( ) ;
if ( ! couponCode ) {
if ( ! couponCode ) {
alert ( 'Пожалуйста, введите код купона.' ) ;
alert ( currentTranslations . error _coupon _empty ) ; // Using translated string
return ;
return ;
}
}
@ -60,64 +93,60 @@ jQuery(document).ready(function($) {
success : function ( response ) {
success : function ( response ) {
if ( response . success ) {
if ( response . success ) {
$ ( document . body ) . trigger ( 'update_checkout' ) ;
$ ( document . body ) . trigger ( 'update_checkout' ) ;
$ ( '#promo_form' ) . hide ( )
$ ( '#promo_form' ) . hide ( ) ;
$ ( '#promo_delete' ) . show ( )
$ ( '#promo_delete' ) . show ( ) ;
$ ( '#promo_err' ) . hide ( )
$ ( '#promo_err' ) . hide ( ) ;
$ ( '#coupon_code_app' ) . val ( 'Применен промокод: ' + couponCode )
$ ( '#coupon_code_app' ) . val ( coupon _applied + ' ' + couponCode ) ;
$ ( '#delete_coupon' ) . data ( 'coupon' , couponCode )
$ ( '#delete_coupon' ) . data ( 'coupon' , couponCode ) ;
} else {
} else {
$ ( '#promo_err' ) . show ( )
$ ( '#promo_err' ) . show ( ) ;
}
}
} ,
} ,
error : function ( ) {
error : function ( ) {
alert ( 'Произошла ошибка. Попробуйте ещё раз.' ) ;
alert ( currentTranslations . error _generic ) ; // Using translated string
}
}
} ) ;
} ) ;
} ) ;
} ) ;
jQuery ( '#pvz_inp' ) . on ( 'click' , function ( ) {
jQuery ( '#pvz_inp' ) . on ( 'click' , function ( ) {
jQuery ( '.open-pvz-btn' ) . click ( )
jQuery ( '.open-pvz-btn' ) . click ( ) ;
} )
} ) ;
$ ( '#address_input input' ) . on ( 'change, input, keyup' , function ( ) {
$ ( '#address_input input' ) . on ( 'change input keyup' , function ( ) {
var address = $ ( '#f_address' ) . val ( )
var address = $ ( '#f_address' ) . val ( ) ;
var apart = $ ( '#f_apartment' ) . val ( )
var apart = $ ( '#f_apartment' ) . val ( ) ;
var floor = $ ( '#f_floor' ) . val ( )
var floor = $ ( '#f_floor' ) . val ( ) ;
var entrance = $ ( '#f_entrance' ) . val ( )
var entrance = $ ( '#f_entrance' ) . val ( ) ;
var number _phone = $ ( '#f_number-phone' ) . val ( )
var number _phone = $ ( '#f_number-phone' ) . val ( ) ;
var address _2 = ''
var address _2 = '' ;
if ( apart ) {
if ( apart ) {
address _2 += ' кв ' + apart
address _2 += ' кв ' + apart ;
}
}
if ( floor ) {
if ( floor ) {
address _2 += ' этаж ' + floor
address _2 += ' этаж ' + floor ;
}
}
if ( entrance ) {
if ( entrance ) {
address _2 += ' подъезд ' + entrance
address _2 += ' подъезд ' + entrance ;
}
}
if ( number _phone ) {
if ( number _phone ) {
address _2 += ' домофон ' + number _phone
address _2 += ' домофон ' + number _phone ;
}
}
$ ( '#addr_inp' ) . val ( address + address _2 )
$ ( '#billing_address_1' ) . val ( address )
$ ( '#billing_address_2' ) . val ( address _2 )
} )
} ) ;
$ ( '#addr_inp' ) . val ( address + address _2 ) ;
$ ( '#billing_address_1' ) . val ( address ) ;
$ ( '#billing_address_2' ) . val ( address _2 ) ;
} ) ;
} ) ;
jQuery ( document ) . ready ( function ( $ ) {
jQuery ( document ) . ready ( function ( $ ) {
$ ( document . body ) . on ( 'checkout_error' , function ( ) {
$ ( document . body ) . on ( 'checkout_error' , function ( ) {
// $('.woocommerce-error').remove();
$ ( '.form-input__error' ) . removeClass ( 'active' ) ;
$ ( '.form-input__error' ) . removeClass ( 'active' ) ;
// // Добавляем ошибки рядом с полями
$ ( '.woocommerce-error li' ) . each ( function ( ) {
$ ( '.woocommerce-error li' ) . each ( function ( ) {
var errorMessage = $ ( this ) . text ( ) . trim ( ) ;
var errorMessage = $ ( this ) . text ( ) . trim ( ) ;
var fieldKey = $ ( this ) . data ( 'id' ) ; // Предполагается, что ошибка содержит data-id
var fieldKey = $ ( this ) . data ( 'id' ) ;
console . log ( errorMessage )
console . log ( fieldKey )
if ( fieldKey ) {
if ( fieldKey ) {
var errorContainer = $ ( '#' + fieldKey + '-error' ) ;
var errorContainer = $ ( '#' + fieldKey + '-error' ) ;
if ( errorContainer . length ) {
if ( errorContainer . length ) {
@ -125,40 +154,35 @@ jQuery(document).ready(function ($) {
$ ( '#' + fieldKey + '-error' ) . addClass ( 'active' ) ;
$ ( '#' + fieldKey + '-error' ) . addClass ( 'active' ) ;
}
}
}
}
if ( errorMessage == 'phone_err' || errorMessage == 'The string supplied did not seem to be a phone number.' || errorMessage . includes ( 'Некорректный номер телефона' ) ) {
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' ) . html ( currentTranslations . phone _number _error ) . addClass ( 'active' ) ; // Using translated string
$ ( '#billing_phone-error' ) . addClass ( 'active' ) ;
}
}
if ( errorMessage == 'Order pickup point not selected.' || errorMessage == 'Не выбран ПВЗ для доставки заказа.' ) {
if ( errorMessage == 'Order pickup point not selected.' || errorMessage == 'Не выбран ПВЗ для доставки заказа.' ) {
$ ( '#pvz-error' ) . html ( 'Не выбран ПВЗ для доставки заказа.' )
$ ( '#pvz-error' ) . html ( currentTranslations . shipping _method _error ) . addClass ( 'active' ) ; // Using translated string
$ ( '#pvz-error' ) . addClass ( 'active' ) ;
}
}
if ( errorMessage == 'adress_error' ) {
if ( errorMessage == 'adress_error' ) {
$ ( '#adr-error' ) . html ( 'Не указан адрес доставки' )
$ ( '#adr-error' ) . html ( currentTranslations . shipping _address _error ) . addClass ( 'active' ) ; // Using translated string
$ ( '#adr-error' ) . addClass ( 'active' ) ;
}
}
if ( errorMessage == 'Неверный адрес эл. почты для выставления счета' ) {
if ( errorMessage == 'Неверный адрес эл. почты для выставления счета' ) {
$ ( '#billing_email-error' ) . html ( errorMessage ) . addClass ( 'active' ) ;
$ ( '#billing_email-error' ) . html ( errorMessage ) . addClass ( 'active' ) ;
}
}
if ( errorMessage == 'Не выбран метод доставки. Пожалуйста перепроверьте ваш адрес или обратитесь за помощью к администрации сайта.' ) {
if ( errorMessage == 'Не выбран метод доставки. Пожалуйста перепроверьте ваш адрес или обратитесь за помощью к администрации сайта.' ) {
$ ( '#billing_city-error' ) . html ( errorMessage ) . addClass ( 'active' ) ;
$ ( '#billing_city-error' ) . html ( errorMessage ) . addClass ( 'active' ) ;
}
}
if ( errorMessage == 'Этот email уже зарегистрирован.' ) {
if ( errorMessage == 'Этот email уже зарегистрирован.' ) {
$ ( '#acc-error' ) . html ( 'Этот email уже зарегистрирован. Войдите в свой аккаунт или укажите другой E-mail.' ) . addClass ( 'active' ) ;
$ ( '#acc-error' ) . html ( currentTranslations . email _taken _error ) . addClass ( 'active' ) ; // Using translated string
}
}
} ) ;
} ) ;
} ) ;
} ) ;
$ ( '#delete_coupon' ) . on ( 'click' , function ( ) {
$ ( '#delete_coupon' ) . on ( 'click' , function ( ) {
$ ( '.woocommerce-remove-coupon[data-coupon=' + $ ( this ) . data ( 'coupon' ) + ']' ) . click ( )
$ ( '.woocommerce-remove-coupon[data-coupon=' + $ ( this ) . data ( 'coupon' ) + ']' ) . click ( ) ;
$ ( '#promo_form' ) . show ( )
$ ( '#promo_form' ) . show ( ) ;
$ ( '#promo_delete' ) . hide ( )
$ ( '#promo_delete' ) . hide ( ) ;
} )
} ) ;
$ ( '.woocommerce-remove-coupon' ) . on ( 'click' , function ( ) {
$ ( '.woocommerce-remove-coupon' ) . on ( 'click' , function ( ) {
$ ( '#promo_form' ) . show ( )
$ ( '#promo_form' ) . show ( ) ;
$ ( '#promo_delete' ) . hide ( )
$ ( '#promo_delete' ) . hide ( ) ;
} )
} ) ;
} ) ;
} ) ;