// --- SAFE GLOBAL FALLBACK: updateQuantity --- // Объявляем глобально и раньше любых обработчиков, чтобы не было ReferenceError. (function ($, w, d) { if (typeof w.updateQuantity !== 'function') { w.updateQuantity = function (productId, quantity) { var ajaxUrl = (w.wc_add_to_cart_params && wc_add_to_cart_params.ajax_url) ? wc_add_to_cart_params.ajax_url : '/wp-admin/admin-ajax.php'; return $.ajax({ url: ajaxUrl, type: 'POST', data: { action: 'update_cart_quantity', product_id: productId, quantity: quantity } }).done(function (response) { // Если Woo отдал фрагменты — обновим их if (response && response.fragments) { $.each(response.fragments, function (key, value) { try { $(key).replaceWith(value); } catch (e) {} }); } // Перерисуем мини-корзину/счётчик, если есть if (typeof w.updateCartButtons === 'function') { try { w.updateCartButtons(); } catch (e) {} } // Триггер Woo try { $(d.body).trigger('wc_fragment_refresh'); } catch (e) {} }).fail(function (xhr, status, error) { console.error('Ошибка AJAX при updateQuantity:', error || status); }); }; } })(jQuery, window, document); // --- /SAFE GLOBAL FALLBACK --- $(document).ready(function() { $('.phone').inputmask('+7 999 999 99 99'); }); $(document).ready(function() { $.fancybox.defaults.hideScrollbar = false; $.fancybox.defaults.animationEffect = "fade"; $.fancybox.defaults.animationDuration = 600; $('[data-fancybox]').fancybox(); }); function toggleMenu($button) { var $menu = $('.pc_menu'); var $menu_fon = $('.pc_menu__fon'); var $body = $('body'); $button.toggleClass('change'); $menu.toggleClass('active'); $menu_fon.toggleClass('active'); if ($menu.hasClass('active')) { $body.addClass('hidden'); $menu_fon.addClass('active'); } else { $body.removeClass('hidden'); $menu_fon.removeClass('active'); } } $('.header-catalog__button').on('click', function () { toggleMenu($(this)); }); $('.pc_menu__fon').on('click', function () { if ($('.pc_menu').hasClass('active')) { toggleMenu($('.header-catalog__button')); } }); $('.pc_menu nav a').on('click', function () { if ($('.pc_menu').hasClass('active')) { toggleMenu($('.header-catalog__button')); } }); function toggleMenu2($button) { var $menu = $('.menu_mob'); var $menu_fon = $('.menu_mob-close'); var $body = $('body'); $button.toggleClass('change'); $menu.toggleClass('active'); $menu_fon.toggleClass('active'); if ($menu.hasClass('active')) { $body.addClass('hidden'); $menu_fon.addClass('active'); } else { $body.removeClass('hidden'); $menu_fon.removeClass('active'); } } $('.header-catalog__button-mob').on('click', function () { toggleMenu2($(this)); }); $('.menu_mob-close').on('click', function () { if ($('.menu_mob').hasClass('active')) { toggleMenu2($('.header-catalog__button-mob')); } }); $(document).ready(function () { $('.catalog_page-menu__item').each(function () { const dropdown = $(this); const dropdownName = dropdown.find('.catalog_page-menu__item-button__icon'); const dropdownContent = dropdown.find('.catalog_page-menu__item-content'); dropdownName.on('click', function () { if (!dropdown.hasClass('all-list')) { dropdown.toggleClass('active'); if (dropdown.hasClass('active')) { dropdownContent.css('max-height', dropdownContent.prop('scrollHeight') + 'px'); } else { dropdownContent.css('max-height', ''); } } }); }); }); $(document).ready(function () { $('.catalog_page-menu__item-content-item').each(function () { const dropdown = $(this); const dropdownName = dropdown.find('.catalog_page-menu__item-content-item-icon'); const dropdownContent = dropdown.find('.catalog_page-menu__item-content-item-content'); dropdownName.on('click', function () { if (!dropdown.hasClass('all-list')) { dropdown.toggleClass('active'); if (dropdown.hasClass('active')) { dropdownContent.css('max-height', dropdownContent.prop('scrollHeight') + 'px'); } else { dropdownContent.css('max-height', ''); } } }); }); }); // Переключатель вида каталога (компактный / расширенный) $(document).ready(function() { var grid = $('.catalog_page-products__grid'); var viewBtns = $('.catalog_page-view-btn'); if (grid.length && viewBtns.length) { var savedView = localStorage.getItem('catalog_view') || 'extended'; grid.addClass('view-' + savedView); viewBtns.each(function() { if ($(this).data('view') === savedView) { $(this).addClass('active'); } }); viewBtns.on('click', function() { var view = $(this).data('view'); grid.removeClass('view-compact view-extended').addClass('view-' + view); viewBtns.removeClass('active'); $(this).addClass('active'); localStorage.setItem('catalog_view', view); }); } }); $(document).ready(function() { $('.catalog_page-count__button').on('click', function() { $(this).toggleClass('active'); $('.catalog_page-count__content').toggleClass('active'); }); $('.catalog_page-count__content-button').on('click', function() { var selectedText = $(this).find('p').text().trim(); var perPage = selectedText === 'Все' ? 'all' : parseInt(selectedText); var url = new URL(window.location.href); url.searchParams.set('per_page', perPage); url.searchParams.delete('paged'); // сбрасываем на первую страницу // Удаляем /page/N/ из URL url.pathname = url.pathname.replace(/\/page\/\d+\/?/, '/'); window.location.href = url.toString(); }); }); $(document).ready(function () { $(".documentation-tab").click(function () { $(".documentation-tab").removeClass("active"); $(".documentation-content").removeClass("active"); $(this).addClass("active"); var index = $(this).index(); $(".documentation-content:eq(" + index + ")").addClass("active"); }); }); $(document).ready(function() { $('.documentation-mob__button').on('click', function() { $(this).toggleClass('active'); $('.documentation-mob__content').toggleClass('active'); }); $('.documentation-mob__item').on('click', function() { $('.documentation-mob__item').removeClass('active'); $(this).addClass('active'); $('.documentation-mob__content, .documentation-mob__button').removeClass('active'); const selectedText = $(this).find('p').text(); $('.documentation-mob__button p').text(selectedText); }); }); $(document).ready(function () { $(".documentation-mob__item").click(function () { $(".documentation-mob__item").removeClass("active"); $(".documentation-content").removeClass("active"); $(this).addClass("active"); var index = $(this).index(); $(".documentation-content:eq(" + index + ")").addClass("active"); }); }); $(document).ready(function () { $(".registration-tab").click(function () { $(".registration-tab").removeClass("active"); $(".registration-content").removeClass("active"); $(this).addClass("active"); var index = $(this).index(); $(".registration-content:eq(" + index + ")").addClass("active"); }); }); $(document).ready(function() { $('.popup-registration__open').on('click', function() { $('.popup-registration').css('display', 'flex'); }); $('.popup-registration__close, .popup-registration__fon').on('click', function() { $('.popup-registration').css('display', 'none'); }); }); $(document).ready(function() { $('.popup-callback__open').on('click', function() { $('.popup-callback').css('display', 'flex'); }); $('.popup-callback__close, .popup-callback__fon').on('click', function() { $('.popup-callback').css('display', 'none'); }); }); $(document).ready(function () { $(".product_page-tab").click(function () { $(".product_page-tab").removeClass("active"); $(".product_page-content").removeClass("active"); $(this).addClass("active"); var index = $(this).index(); $(".product_page-content:eq(" + index + ")").addClass("active"); }); }); $(document).ready(function() { $('.product_page-tabs__mob-button').on('click', function() { $(this).toggleClass('active'); $('.product_page-tabs__mob-content').toggleClass('active'); }); $('.product_page-tabs__mob-tab').on('click', function() { $('.product_page-tabs__mob-tab').removeClass('active'); $(this).addClass('active'); $('.product_page-tabs__mob-content, .product_page-tabs__mob-button').removeClass('active'); const selectedText = $(this).find('p').text(); $('.product_page-tabs__mob-button p').text(selectedText); }); }); $(document).ready(function () { $(".product_page-tabs__mob-tab").click(function () { $(".product_page-tabs__mob-tab").removeClass("active"); $(".product_page-content").removeClass("active"); $(this).addClass("active"); var index = $(this).index(); $(".product_page-content:eq(" + index + ")").addClass("active"); }); }); $(document).ready(function() { $('.popup-cart__open').on('click', function() { $('.popup-cart').css('display', 'flex'); }); $('.popup-cart__close, .popup-cart__fon').on('click', function() { $('.popup-cart').css('display', 'none'); }); }); $(document).ready(function() { $('.popup-cart-product__open').on('click', function() { $('.popup-cart-product').css('display', 'flex'); }); $('.popup-cart-product__close, .popup-cart-product__fon').on('click', function() { $('.popup-cart-product').css('display', 'none'); }); }); $(document).ready(function () { // Функция автозаполнения полей из профиля function fillCheckoutFields(tabIndex) { if (typeof orgstekloCheckoutUser === 'undefined' || !orgstekloCheckoutUser.isLoggedIn) return; var u = orgstekloCheckoutUser; if (tabIndex === 0) { $('#billing_fio').val(u.fio || ''); $('#billing_phone_phys').val(u.phone || ''); $('#billing_email_phys').val(u.email || ''); } else if (tabIndex === 1) { $('#billing_company_name').val(u.company_name || ''); $('#billing_inn').val(u.inn || ''); $('#billing_kpp').val(u.kpp || ''); $('#billing_legal_address').val(u.legal_address || ''); $('#billing_actual_address').val(u.actual_address || ''); $('#billing_contact_person').val(u.fio || ''); $('#billing_phone_legal').val(u.phone || ''); $('#billing_email_legal').val(u.email || ''); } } $(".checkout-data__tab").click(function () { $(".checkout-data__tab").removeClass("active"); $(".checkout-data__content").removeClass("active"); $(this).addClass("active"); var index = $(this).index(); $(".checkout-data__content").eq(index).addClass("active"); // Проверка на авторизацию var isLoggedIn = $('body').hasClass('logged-in'); if (index === 1 && !isLoggedIn) { // Блокировка кнопки $("#place_order").prop("disabled", true); // Скрыть consult-checkbox, показать checkout-description $(".consult-checkbox").hide(); $(".checkout-description").show(); } else { // Разблокировать кнопку $("#place_order").prop("disabled", false); // Показать consult-checkbox, скрыть checkout-description $(".consult-checkbox").show(); $(".checkout-description").hide(); } // Автозаполнение полей fillCheckoutFields(index); // Обновить видимость способов оплаты if (typeof updatePaymentMethodVisibility === 'function') { updatePaymentMethodVisibility(); } }); // Автозаполнение при загрузке страницы (активный таб по умолчанию) fillCheckoutFields($(".checkout-data__tab.active").index()); }); $(document).ready(function() { $('.lk-menu__mobile-button').on('click', function() { $(this).toggleClass('active'); $('.lk-menu__mobile-content').toggleClass('active'); }); $('.lk-menu__mobile-content__link').on('click', function() { $('.lk-menu__mobile-content__link').removeClass('active'); $(this).addClass('active'); $('.lk-menu__mobile-content, .lk-menu__mobile-button').removeClass('active'); const selectedText = $(this).find('p').text(); $('.lk-menu__mobile-button p').text(selectedText); }); }); $(document).ready(function() { $('.popup-password_change__open').on('click', function() { $('.popup-password_change').css('display', 'flex'); }); $('.popup-password_change__close, .popup-password_change__fon').on('click', function() { $('.popup-password_change').css('display', 'none'); }); }); $(document).ready(function() { $('.popup-email_change__open').on('click', function() { $('.popup-email_change').css('display', 'flex'); }); $('.popup-email_change__close, .popup-email_change__fon').on('click', function() { $('.popup-email_change').css('display', 'none'); }); }); $(document).ready(function() { $('.popup-delete_acc__open').on('click', function() { $('.popup-delete_acc').css('display', 'flex'); }); $('.popup-delete_acc__close, .popup-delete_acc__fon').on('click', function() { $('.popup-delete_acc').css('display', 'none'); }); }); $(document).ready(function() { function openMinicart() { $('.minicart__fon').css('display', 'flex'); $('.minicart').css('display', 'flex'); $('body').css('overflow', 'hidden'); } function closeMinicart() { $('.minicart__fon').css('display', 'none'); $('.minicart').css('display', 'none'); $('body').css('overflow', 'auto'); } $('.minicart-open').on('click mouseenter', openMinicart); $('.minicart__fon').on('click', closeMinicart); // Закрытие при уходе курсора с .minicart и .minicart-open let minicartHover = false; $('.minicart, .minicart-open').on('mouseenter', function() { minicartHover = true; }); $('.minicart, .minicart-open').on('mouseleave', function() { minicartHover = false; setTimeout(function() { if (!minicartHover) { closeMinicart(); } }, 500); // задержка нужна, чтобы не срабатывало при переходе между элементами }); }); $(document).ready(function() { const $menuColumns = $('.menu_mob-column, .menu_mob-logo'); const $menuContents = $('.menu_mob-menu__content'); $menuContents.hide(); $('.menu_mob-menu__button').on('click', function() { $menuContents.hide(); const contentId = $(this).data('content'); $menuColumns.hide(); $menuContents.filter('[data-content="' + contentId + '"]').show(); }); $('.menu_mob-menu__content-back').on('click', function() { $menuContents.hide(); $(this).closest('.menu_mob-menu__content').hide(); $menuColumns.show(); }); }); jQuery(document).ready(function($) { $('.projects-more_page').on('click', function() { const hiddenItems = $('.projects-item.hidden'); hiddenItems.slice(0, 6).removeClass('hidden'); if ($('.projects-item.hidden').length === 0) { $(this).hide(); } }); }); jQuery(document).ready(function($) { $('.documentation-more').on('click', function() { const $container = $(this).closest('.documentation-content'); $container.find('.documentation-item.hidden').removeClass('hidden'); $(this).hide(); }); }); //login jQuery(document).ready(function($) { $('#login-form').on('submit', function(e) { e.preventDefault(); const phone = $('#login-form input[type=tel]').val(); const password = $('#login-form #login-password').val(); $.ajax({ url: '/wp-admin/admin-ajax.php', type: 'POST', data: { action: 'login_by_phone', phone: phone, password: password }, success: function(response) { if (response.success) { window.location.href = '/account'; } else { $('.login-error').show(); } } }); }); }); jQuery(document).ready(function($) { $('.login-password__button').on('click', function() { const $button = $(this); const $container = $button.closest('.login-form__input'); const $input = $container.find('input'); const $img = $button.find('img'); if ($input.attr('type') === 'password') { $input.attr('type', 'text'); $img.attr('src', '/wp-content/uploads/2025/05/password.svg'); } else { $input.attr('type', 'password'); $img.attr('src', '/wp-content/uploads/2025/05/password-2.svg'); } }); }); jQuery(document).ready(function($) { $('#recovery-form').on('submit', function(e) { e.preventDefault(); const email = $(this).find('input[name="user_email"]').val(); $.ajax({ url: '/wp-admin/admin-ajax.php', type: 'POST', data: { action: 'custom_password_reset', user_email: email }, success: function(response) { if (response.success) { window.location.href = '/password-sent'; } else { $('.login-error').fadeIn(); } } }); }); }); jQuery(document).ready(function($) { $('#home_categories_more').on('click', function(e) { e.preventDefault(); $('.categories-item.hidden').slideDown().removeClass('hidden'); $(this).remove(); }); }); jQuery(document).ready(function($) { let verificationCode = ''; let timerInterval; function startTimer($timerElement, $resendButton) { let timeLeft = 120; $timerElement.show(); $resendButton.hide(); timerInterval = setInterval(function () { timeLeft--; const minutes = String(Math.floor(timeLeft / 60)).padStart(2, '0'); const seconds = String(timeLeft % 60).padStart(2, '0'); $timerElement.text(`Отправить код повторно через ${minutes}:${seconds}`); if (timeLeft <= 0) { clearInterval(timerInterval); $timerElement.hide(); $resendButton.show(); } }, 1000); } function sendSMS(phone, callback) { $.ajax({ url: '/wp-admin/admin-ajax.php', method: 'POST', data: { action: 'send_sms_code', phone: phone }, success: function(response) { if (response.success) { verificationCode = response.data.code; callback(); } else { alert(response.data.message || 'Ошибка отправки SMS'); } } }); } $('.registration-form').on('submit', function(e) { e.preventDefault(); const $form = $(this); const email = $form.find('input[type=email]').val(); const phone = $form.find('input[type=tel]').val(); const password = $form.find('input[type=password]').val(); const registration_type = $form.find('input[name=registration_type]').val(); const checkbox = $form.find('input[name="login-form__remember"]'); if (!checkbox.is(':checked')) { alert('Подтвердите согласие с политикой конфиденциальности'); return; } $.ajax({ url: '/wp-admin/admin-ajax.php', method: 'POST', data: { action: 'check_email_exists', email: email }, success: function(response) { if (response.exists) { $('.login-error').css('display', 'flex'); } else { sendSMS(phone, function() { $('.popup-registration').css('display', 'flex'); $('.popup-registration__name b').text(phone); startTimer($('.popup-registration p:contains("через")'), $('.popup-registration__code-button')); $('.popup-registration__submit').off('click').on('click', function(e) { e.preventDefault(); const enteredCode = $('.popup-registration__input input').val(); $.ajax({ url: '/wp-admin/admin-ajax.php', method: 'POST', data: { action: 'register_user', email: email, password: password, phone: phone, registration_type: registration_type, code: enteredCode }, success: function(res) { if (res.success) { window.location.href = '/registration-success'; } else { alert(res.data.message); } } }); }); }); } } }); }); $('.popup-registration__code-button').on('click', function(e) { e.preventDefault(); const phone = $('.popup-registration__name b').text(); sendSMS(phone, function() { startTimer($('.popup-registration p:contains("через")'), $('.popup-registration__code-button')); }); }); }); jQuery(document).ready(function ($) { $('.popup-delete_acc-yes').on('click', function (e) { e.preventDefault(); $.ajax({ type: 'POST', url: '/wp-admin/admin-ajax.php', data: { action: 'delete_my_account' }, success: function () { window.location.href = '/'; // редирект после удаления }, error: function () { console.error('Ошибка при удалении аккаунта.'); } }); }); }); jQuery(document).ready(function ($) { // Сохранение формы профиля $('.profile-individual').on('submit', function (e) { e.preventDefault(); const name = $('.profile input[placeholder="ФИО*"]').val(); const phone = $('.profile input[type="tel"]').val(); const email = $('.profile input[type="email"]').val(); $.ajax({ type: 'POST', url: '/wp-admin/admin-ajax.php', data: { action: 'save_user_profile_data', name: name, phone: phone, email: email }, success: function (response) { if (response.success) { alert('Данные сохранены'); } else { alert('Ошибка: ' + response.data.message); } }, }); }); }); jQuery(document).ready(function ($) { // Сохранение формы профиля $('.profile-legal').on('submit', function (e) { e.preventDefault(); const name = $('.profile input[placeholder="ФИО*"]').val(); const phone = $('.profile input[type="tel"]').val(); const email = $('.profile input[type="email"]').val(); const company_name = $('.profile input[placeholder="Наименование организации*"]').val(); const inn = $('.profile input[placeholder="ИНН*"]').val(); const kpp = $('.profile input[placeholder="КПП"]').val(); const legal_address = $('.profile input[placeholder="Юридический адрес*"]').val(); const actual_address = $('.profile input[placeholder="Фактический адрес*"]').val(); $.ajax({ type: 'POST', url: '/wp-admin/admin-ajax.php', data: { action: 'save_user_profile_data2', name: name, phone: phone, email: email, company_name: company_name, // <-- Добавлено inn: inn, // <-- Добавлено kpp: kpp, // <-- Добавлено legal_address: legal_address, // <-- Добавлено actual_address: actual_address }, success: function(response) { if (response.success) { alert('Данные сохранены'); } }, }); }); }); jQuery(document).ready(function ($) { $('#send-verification-email').on('click', function () { $.post('/wp-admin/admin-ajax.php', { action: 'send_email_verification_link' }, function (res) { if (res.success) { $('.popup-email_change').css('display', 'flex'); } else { alert('Ошибка: ' + res.data.message); } }); }); }); jQuery(document).ready(function ($) { const $changeBtn = $('.profile-password__change'); const $currentPassBlock = $('.profile-password__col'); const $currentPassInput = $('.profile-password__col .individual_old_input'); const $newPassBlock = $('.profile-password__col-new'); const $saveNewPassBtn = $('.profile-password__new-submit'); const $popup = $('.popup-password_change'); $changeBtn.on('click', function () { const currentPassword = $currentPassInput.val(); if (currentPassword.length < 6) { alert('Введите текущий пароль (не менее 6 символов)'); return; } $.post('/wp-admin/admin-ajax.php', { action: 'check_user_password', password: currentPassword }, function (response) { if (response.success) { $changeBtn.hide(); $currentPassBlock.hide(); $newPassBlock.show(); } else { alert('Неверный текущий пароль'); } }); }); $saveNewPassBtn.on('click', function () { const oldPass = $newPassBlock.find('input[placeholder="Старый пароль"]').val(); const newPass = $newPassBlock.find('input[placeholder="Новый пароль"]').val(); if (newPass.length < 6) { alert('Новый пароль должен быть не менее 6 символов'); return; } $.post('/wp-admin/admin-ajax.php', { action: 'change_user_password', old_password: oldPass, new_password: newPass }, function (response) { if (response.success) { $popup.css('display', 'flex'); } else { alert(response.message || 'Ошибка при смене пароля'); } }); }); }); jQuery(document).ready(function($) { $('.profile-password__button').on('click', function() { const $button = $(this); const $container = $button.closest('.profile-input'); const $input = $container.find('input'); const $img = $button.find('img'); if ($input.attr('type') === 'password') { $input.attr('type', 'text'); $img.attr('src', '/wp-content/uploads/2025/05/password.svg'); } else { $input.attr('type', 'password'); $img.attr('src', '/wp-content/uploads/2025/05/password-2.svg'); } }); }); jQuery(document).ready(function($) { $('form.product_page-kley').on('show_variation', function(event, variation) { const priceHtml = variation.price_html; const $temp = $('
' + newPrice + '
'; } if (oldPrice) { newHtml += '' + oldPrice + '
'; } $('.product_page-calc__one-row').html(newHtml); }); }); jQuery(document).ready(function($) { $('form.product_page-trubi').on('show_variation', function(event, variation) { const priceHtml = variation.price_html; const $temp = $('' + newPrice + '
'; } if (oldPrice) { newHtml += '' + oldPrice + '
'; } $('.product_page-calc__one-row').html(newHtml); }); }); jQuery(document).ready(function($) { $('form.product_page-sterjni').on('show_variation', function(event, variation) { const priceHtml = variation.price_html; const $temp = $('' + newPrice + '
'; } if (oldPrice) { newHtml += '' + oldPrice + '
'; } $('.product_page-calc__one-row').html(newHtml); }); }); jQuery(document).ready(function($) { const priceHtml = $('.summary .price').html(); const $temp = $('' + newPrice + '
'; } if (oldPrice) { newHtml += '' + oldPrice + '
'; } $('.product_page-calc__one-row').html(newHtml); }); jQuery(function ($) { const $form = $('form.product_page-kley'); function updateTotals(variation, qty) { if (!variation) return; const weight = parseFloat(variation.weight) || 0; const totalWeight = (weight * qty).toFixed(3); $('.product_page-weight p:last-child').text(totalWeight + ' кг'); // Используем raw_price - точная цена как в корзине (get_price()) const newPrice = parseFloat(variation.raw_price) || parseFloat(variation.display_price) || 0; const oldPrice = parseFloat(variation.raw_regular_price) || parseFloat(variation.display_regular_price) || 0; // Считаем как корзина: цена * кол-во, потом округление const totalNew = Math.round(newPrice * qty).toLocaleString('ru-RU'); const totalOld = Math.round(oldPrice * qty).toLocaleString('ru-RU'); $('.product_page-price').html(totalNew + ' ₽'); if (oldPrice && oldPrice > newPrice) { $('.product_page-oldprice').show().html(totalOld + ' ₽'); } else { $('.product_page-oldprice').hide(); } } $form.on('show_variation', function (event, variation) { const qty = parseInt($('.qty').val(), 10) || 1; updateTotals(variation, qty); }); $('body').on('input change', '.qty', function () { const variationID = $('.variation_id').val(); const variations = $form.data('product_variations') || []; const variation = variations.find(v => v.variation_id == variationID); if (variation) { const qty = parseInt($(this).val(), 10) || 1; updateTotals(variation, qty); } }); }); jQuery(function ($) { const $form = $('form.product_page-trubi'); function updateTotals(variation, qty) { if (!variation) return; const weight = parseFloat(variation.weight) || 0; const totalWeight = (weight * qty).toFixed(3); $('.product_page-weight p:last-child').text(totalWeight + ' кг'); // Используем raw_price - точная цена как в корзине (get_price()) const newPrice = parseFloat(variation.raw_price) || parseFloat(variation.display_price) || 0; const oldPrice = parseFloat(variation.raw_regular_price) || parseFloat(variation.display_regular_price) || 0; // Считаем как корзина: цена * кол-во, потом округление const totalNew = Math.round(newPrice * qty).toLocaleString('ru-RU'); const totalOld = Math.round(oldPrice * qty).toLocaleString('ru-RU'); $('.product_page-price').html(totalNew + ' ₽'); if (oldPrice && oldPrice > newPrice) { $('.product_page-oldprice').show().html(totalOld + ' ₽'); } else { $('.product_page-oldprice').hide(); } } $form.on('show_variation', function (event, variation) { const qty = parseInt($('.qty').val(), 10) || 1; updateTotals(variation, qty); }); $('body').on('input change', '.qty', function () { const variationID = $('.variation_id').val(); const variations = $form.data('product_variations') || []; const variation = variations.find(v => v.variation_id == variationID); if (variation) { const qty = parseInt($(this).val(), 10) || 1; updateTotals(variation, qty); } }); }); jQuery(function ($) { const $form = $('form.product_page-sterjni'); function updateTotals(variation, qty) { if (!variation) return; const weight = parseFloat(variation.weight) || 0; const totalWeight = (weight * qty).toFixed(3); $('.product_page-weight p:last-child').text(totalWeight + ' кг'); // Используем raw_price - точная цена как в корзине (get_price()) const newPrice = parseFloat(variation.raw_price) || parseFloat(variation.display_price) || 0; const oldPrice = parseFloat(variation.raw_regular_price) || parseFloat(variation.display_regular_price) || 0; // Считаем как корзина: цена * кол-во, потом округление const totalNew = Math.round(newPrice * qty).toLocaleString('ru-RU'); const totalOld = Math.round(oldPrice * qty).toLocaleString('ru-RU'); $('.product_page-price').html(totalNew + ' ₽'); if (oldPrice && oldPrice > newPrice) { $('.product_page-oldprice').show().html(totalOld + ' ₽'); } else { $('.product_page-oldprice').hide(); } } $form.on('show_variation', function (event, variation) { const qty = parseInt($('.qty').val(), 10) || 1; updateTotals(variation, qty); }); $('body').on('input change', '.qty', function () { const variationID = $('.variation_id').val(); const variations = $form.data('product_variations') || []; const variation = variations.find(v => v.variation_id == variationID); if (variation) { const qty = parseInt($(this).val(), 10) || 1; updateTotals(variation, qty); } }); }); jQuery(function ($) { // Работает только на простом товаре if (!$('form.product_page-simple').length) { return; } function parsePrice(text) { // Сначала заменяем запятую на точку (десятичный разделитель в RU) // Потом удаляем пробелы и символ валюты return parseFloat(text.replace(',', '.').replace(/\s|₽/g, '')) || 0; } function updateTotals() { const qty = parseInt($('.qty').val(), 10) || 1; // Приоритет: используем скрытые элементы с чистыми ценами (если есть) // Это гарантирует точное совпадение с серверным расчётом let newPrice = parseFloat($('.simple-price').data('price')) || 0; let oldPrice = parseFloat($('.simple-price').data('regular-price')) || 0; // Fallback: парсим из .price HTML если скрытые элементы не найдены if (!newPrice) { const priceHtml = $('.price').html() || ''; const $temp = $('${item.price} ${oldPriceHtml}