diff --git a/wp-content/themes/cosmopet/functions.php b/wp-content/themes/cosmopet/functions.php index 0c95761..f0953ab 100644 --- a/wp-content/themes/cosmopet/functions.php +++ b/wp-content/themes/cosmopet/functions.php @@ -595,4 +595,5 @@ register_sidebar( array( ) ); -add_filter( 'woocommerce_price_trim_zeros', '__return_true' ); \ No newline at end of file +add_filter( 'woocommerce_price_trim_zeros', '__return_true' ); + diff --git a/wp-content/themes/cosmopet/global-functions/multilang-functions.php b/wp-content/themes/cosmopet/global-functions/multilang-functions.php index e69de29..7bf81c6 100644 --- a/wp-content/themes/cosmopet/global-functions/multilang-functions.php +++ b/wp-content/themes/cosmopet/global-functions/multilang-functions.php @@ -0,0 +1,43 @@ +скидку!', 'Узнайте о нас больше и получите скидку!'); + pll_register_string ('Это миф!', 'Это миф!'); + pll_register_string ('Это правда!', 'Это правда!'); + pll_register_string ('Правда', 'Правда'); + pll_register_string ('Миф', 'Миф'); + pll_register_string ('Далее', 'Далее'); + pll_register_string ('ваш результат', 'ваш результат'); + pll_register_string ('Скопировать', 'Скопировать'); + pll_register_string ('Скопировано', 'Скопировано'); + pll_register_string ('В магазин', 'В магазин'); + pll_register_string ('Наш блог', 'Наш блог'); + pll_register_string ('Новости рынка кормов и экологии, полезные статьи о здоровье домашних животных', 'Новости рынка кормов и экологии, полезные статьи о здоровье домашних животных'); + pll_register_string ('ЭТАПЫ ПРОИЗВОД­СТВА', 'ЭТАПЫ ПРОИЗВОД­СТВА'); + pll_register_string ('Этапы производс­тва корма', 'Этапы производс­тва корма'); + pll_register_string ('Все статьи', 'Все статьи'); + pll_register_string ('Узнать больше', 'Узнать больше'); +}); + diff --git a/wp-content/themes/cosmopet/modules/layout/assets/js/_gp-function.js b/wp-content/themes/cosmopet/modules/layout/assets/js/_gp-function.js index d76ad0b..e69de29 100644 --- a/wp-content/themes/cosmopet/modules/layout/assets/js/_gp-function.js +++ b/wp-content/themes/cosmopet/modules/layout/assets/js/_gp-function.js @@ -1,166 +0,0 @@ -// 'use strict'; - -// // Глобальные переменные для управления состоянием -// let currentModalContent = null; - -// function modalOpen(buttonElement, contentElement) { -// const modal = document.querySelector('.modal'); -// const aside = document.querySelector('.modal__aside'); -// const elements = document.querySelectorAll(buttonElement); -// const device = window.screen.width; - -// // Обработчик закрытия по клику на оверлей -// modal.addEventListener('click', function(e) { -// if (e.target === modal && currentModalContent) { -// closeModal(currentModalContent); -// } -// }); - -// // Обработчик закрытия по Escape -// document.addEventListener('keydown', function(e) { -// if (e.key === 'Escape' && currentModalContent) { -// closeModal(currentModalContent); -// } -// }); - -// elements.forEach(e => { -// e.addEventListener('click', function() { -// const content = document.querySelector(contentElement); -// currentModalContent = content; - -// // Сброс стилей перед открытием -// resetModalStyles(); - -// modal.classList.add('active'); -// content.classList.add('active'); - -// const width = content.clientWidth; - -// setTimeout(() => { -// if (device <= 720) { -// aside.style.width = `${device}px`; -// } else { -// aside.style.width = `${width}px`; -// } -// content.style.opacity = '1'; -// content.style.filter = 'blur(0)'; -// }, 10); -// }); -// }); -// } - -// function modalClose(buttonElement) { -// const elements = document.querySelectorAll(buttonElement); - -// elements.forEach(e => { -// e.addEventListener('click', function() { -// if (currentModalContent) { -// closeModal(currentModalContent); -// } -// }); -// }); -// } - -// function closeModal(contentElement) { -// const modal = document.querySelector('.modal'); -// const aside = document.querySelector('.modal__aside'); - -// aside.style.width = '0'; -// contentElement.style.opacity = '0'; -// contentElement.style.filter = 'blur(10px)'; - -// setTimeout(() => { -// contentElement.classList.remove('active'); -// modal.classList.remove('active'); -// currentModalContent = null; -// }, 300); -// } - -// function resetModalStyles() { -// const allModals = document.querySelectorAll('.modal__item'); - -// allModals.forEach(modal => { -// modal.style.opacity = ''; -// modal.style.filter = ''; -// modal.classList.remove('active'); -// }); - -// document.querySelector('.modal__aside').style.width = ''; -// } -// function toggleOpenX(mainElement, buttonElement ,heightElement, contentElement, close) { -// let elements = document.querySelectorAll(mainElement); - -// elements.forEach(e => { -// let thisMainElement = e, -// thisButtonElement = e.querySelector(buttonElement), -// thisHeightElement = e.querySelector(heightElement), -// thisContentElement = e.querySelector(contentElement); - -// thisButtonElement.onclick = function (e) { -// let height = thisHeightElement.clientHeight; - -// if (close == true && !thisMainElement.classList.contains('active')) { -// elements.forEach(e => { -// if (e.classList.contains('active')) { -// e.classList.remove('active'); -// e.querySelector(contentElement).style.height = null -// } -// }) -// } - -// if (!thisMainElement.classList.contains('active')) { -// thisContentElement.style.height = `${height}px`; -// thisMainElement.classList.add('active'); -// }else{ -// thisContentElement.style.height = null; -// thisMainElement.classList.remove('active'); -// } -// } - -// }); -// } - -// function toggleHeader(button, content, blockheight, removeBlock, removeClass) { -// let thisButton = document.querySelector(button), -// thisContent = document.querySelector(content), -// thisRemoveBlock = document.querySelector(removeBlock) || '', -// thisBlockheight = document.querySelector(blockheight); - -// thisButton.onclick = function () { -// let height = thisBlockheight.clientHeight; - -// if (!thisContent.classList .contains('open')) { -// thisContent.style.height = `${height}px`; -// thisContent.classList .add('open'); - -// if (removeBlock) { -// thisRemoveBlock.classList.remove(removeClass); -// } -// }else{ -// thisContent.style.height = null; -// thisContent.classList .remove('open'); - -// if (removeBlock) { -// if (window.scrollY <= 25) { -// thisRemoveBlock.classList.add(removeClass); -// } -// } -// } -// } -// } - -// function modalFormOpen(formOrNotification) { -// let buttons = document.querySelectorAll(formOrNotification), -// modal = document.querySelector('.modal'); - -// buttons.forEach(button => { -// button.onclick = function (eventButton) { -// let classOpenForm = button.dataset.form, -// form = modal.querySelector(`.${classOpenForm}`); - -// form.classList.add('active'); -// modal.classList.add('active'); -// } -// }) -// } -// // function \ No newline at end of file diff --git a/wp-content/themes/cosmopet/modules/layout/module-controller.php b/wp-content/themes/cosmopet/modules/layout/module-controller.php index e3a0b36..08e4f89 100644 --- a/wp-content/themes/cosmopet/modules/layout/module-controller.php +++ b/wp-content/themes/cosmopet/modules/layout/module-controller.php @@ -3,4 +3,5 @@ include_module('header'); include_component('shop', 'cart'); +include_module('shop'); include_module('footer'); diff --git a/wp-content/themes/cosmopet/modules/shop/components/cart/assets/js/cart.js b/wp-content/themes/cosmopet/modules/shop/components/cart/assets/js/cart.js index bcef82e..2baf238 100644 --- a/wp-content/themes/cosmopet/modules/shop/components/cart/assets/js/cart.js +++ b/wp-content/themes/cosmopet/modules/shop/components/cart/assets/js/cart.js @@ -18,7 +18,7 @@ jQuery(document).ready(function($) { }); // Увеличение количества - $(document).on('click', '.counter__button.plus', function(e) { + $(document).on('click', '.modal__basket .counter__button.plus', function(e) { e.preventDefault(); const key = $(this).data('key'); const input = $(this).siblings('.counter__input'); @@ -27,7 +27,7 @@ jQuery(document).ready(function($) { }); // Уменьшение количества - $(document).on('click', '.counter__button.minus', function(e) { + $(document).on('click', '.modal__basket .counter__button.minus', function(e) { e.preventDefault(); const key = $(this).data('key'); const input = $(this).siblings('.counter__input'); diff --git a/wp-content/themes/cosmopet/modules/shop/components/cart/component-controller.php b/wp-content/themes/cosmopet/modules/shop/components/cart/component-controller.php index bfad3cb..e69de29 100644 --- a/wp-content/themes/cosmopet/modules/shop/components/cart/component-controller.php +++ b/wp-content/themes/cosmopet/modules/shop/components/cart/component-controller.php @@ -1,8 +0,0 @@ - 'Код купона не указан.' ) ); + } + + // Применение купона + $applied = WC()->cart->apply_coupon( $coupon_code ); + + if ( $applied ) { + wp_send_json_success(); + } else { + wp_send_json_error( array( 'message' => 'Купон не применён. Проверьте код.' ) ); + } +} + + +/** + * Обработчик AJAX для обновления количества товара в корзине + */ +add_action('wp_ajax_update_cart_quantity', 'update_cart_quantity_handler'); +add_action('wp_ajax_nopriv_update_cart_quantity', 'update_cart_quantity_handler'); + +function update_cart_quantity_handler() { + if (!isset($_POST['cart_item_key']) || !isset($_POST['quantity'])) { + wp_send_json_error('Недостаточно данных'); + return; + } + + $cart_item_key = sanitize_text_field($_POST['cart_item_key']); + $quantity = intval($_POST['quantity']); + + if ($quantity <= 0) { + wp_send_json_error('Некорректное количество'); + return; + } + + $cart = WC()->cart; + $cart_item = $cart->get_cart_item($cart_item_key); + + if (!$cart_item) { + wp_send_json_error('Товар не найден в корзине'); + return; + } + + $updated = $cart->set_quantity($cart_item_key, $quantity); + + if ($updated) { + wp_send_json_success(); + } else { + wp_send_json_error('Не удалось обновить количество'); + } +} + +/** + * Обработчик AJAX для восстановления товара в корзине + */ +add_action('wp_ajax_restore_cart_item', 'restore_cart_item_handler'); +add_action('wp_ajax_nopriv_restore_cart_item', 'restore_cart_item_handler'); + +function restore_cart_item_handler() { + if (!isset($_POST['product_id']) || !isset($_POST['quantity'])) { + wp_send_json_error('Недостаточно данных'); + return; + } + + $product_id = intval($_POST['product_id']); + $variation_id = isset($_POST['variation_id']) ? intval($_POST['variation_id']) : 0; + $quantity = intval($_POST['quantity']); + + if ($quantity <= 0) { + wp_send_json_error('Некорректное количество'); + return; + } + + $cart = WC()->cart; + $cart_item_key = $cart->add_to_cart($product_id, $quantity, $variation_id); + + if ($cart_item_key) { + wp_send_json_success(); + } else { + wp_send_json_error('Не удалось восстановить товар'); + } +} + +/** + * Обработчик AJAX для получения фрагментов корзины + */ +add_action('wp_ajax_get_cart_fragment', 'get_cart_fragment_handler'); +add_action('wp_ajax_nopriv_get_cart_fragment', 'get_cart_fragment_handler'); + +function get_cart_fragment_handler() { + ob_start(); + Timber::render('shop/cart-contents.twig', Timber::context()); + $contents = ob_get_clean(); + + $response = array( + 'contents' => $contents, + 'total' => WC()->cart->get_cart_total(), + 'count' => WC()->cart->get_cart_contents_count() + ); + + wp_send_json_success($response); +} + + +/** + * Инициализация WooCommerce AJAX + */ +add_action('wp_enqueue_scripts', 'enqueue_woocommerce_ajax_scripts'); +function enqueue_woocommerce_ajax_scripts() { + wp_localize_script('jquery', 'woocommerce_params', array( + 'ajax_url' => admin_url('admin-ajax.php'), + 'currency_symbol' => get_woocommerce_currency_symbol(), + 'currency_format' => str_replace(array('%1$s', '%2$s'), array('%s', '%v'), get_woocommerce_price_format()), + 'i18n_restore_item' => pll_e('Восстановить', 'woocommerce') + )); +} + +add_action('wp_ajax_remove_cart_item', 'handle_remove_cart_item'); +add_action('wp_ajax_nopriv_remove_cart_item', 'handle_remove_cart_item'); + +function handle_remove_cart_item() { + if (!isset($_POST['cart_item_key'])) { + wp_send_json_error('Не указан ключ элемента корзины'); + return; + } + + $cart_item_key = sanitize_text_field($_POST['cart_item_key']); + $cart = WC()->cart; + + if ($cart->remove_cart_item($cart_item_key)) { + wp_send_json_success(); + } else { + wp_send_json_error('Не удалось удалить товар из корзины'); + } +} \ No newline at end of file diff --git a/wp-content/themes/cosmopet/modules/shop/module-controller.php b/wp-content/themes/cosmopet/modules/shop/module-controller.php index e69de29..329d624 100644 --- a/wp-content/themes/cosmopet/modules/shop/module-controller.php +++ b/wp-content/themes/cosmopet/modules/shop/module-controller.php @@ -0,0 +1,323 @@ + 'text', + 'label' => __('Имя', 'woocommerce'), + 'placeholder' => __('Ваше имя', 'woocommerce'), + 'required' => true, + 'class' => array('form-row-wide'), + 'priority' => 10, + ); + $fields['billing']['billing_last_name'] = array( + 'type' => 'text', + 'label' => __('Фамилия', 'woocommerce'), + 'placeholder' => __('Ваша фамилия', 'woocommerce'), + 'required' => true, + 'class' => array('form-row-wide'), + 'priority' => 10, + ); + $fields['billing']['billing_email'] = array( + 'type' => 'email', + 'label' => __('E-mail', 'woocommerce'), + 'placeholder' => __('Начните вводить ваш email', 'woocommerce'), + 'required' => true, + 'class' => array('form-row-wide'), + 'priority' => 20, + ); + $fields['billing']['billing_phone'] = array( + 'type' => 'tel', + 'label' => __('Телефон', 'woocommerce'), + 'placeholder' => __('+7 ___ ___ ____', 'woocommerce'), + 'required' => true, + 'class' => array('form-row-wide'), + 'priority' => 30, + ); + $fields['billing']['billing_city'] = array( + 'type' => 'text', + 'label' => __('Населенный пункт', 'woocommerce'), + 'placeholder' => __('Ваш город', 'woocommerce'), + 'required' => true, + 'class' => array('form-row-wide'), + 'priority' => 40, + ); + + $fields['billing']['billing_address_1'] = array( + 'type' => 'text', + 'label' => __('Адрес', 'woocommerce'), + 'placeholder' => __('Адрес', 'woocommerce'), + 'required' => false, + 'class' => array('visually-hidden'), + 'priority' => 40, + ); + $fields['billing']['billing_address_2'] = array( + 'type' => 'text', + 'label' => __('Адрес 2', 'woocommerce'), + 'placeholder' => __('Адрес 2', 'woocommerce'), + 'required' => false, + 'class' => array('visually-hidden'), + 'priority' => 40, + ); + + return $fields; +} +// remove_action( 'woocommerce_review_order_before_payment', 'woocommerce_review_order_shipping' ); + +add_action( 'init', function() { + update_option( 'woocommerce_enable_coupons', 'yes' ); // Включение купонов +} ); + +add_filter( 'woocommerce_available_payment_gateways', 'set_default_payment_gateway' ); + +function set_default_payment_gateway( $available_gateways ) { + if ( is_cart() || is_checkout() ) { + // Устанавливаем способ оплаты по умолчанию + $default_payment_gateway = 'tbank'; // ID способа оплаты, например 'cod' для "наличными при доставке" + + // Проверяем, доступен ли этот способ оплаты + if ( isset( $available_gateways[ $default_payment_gateway ] ) ) { + foreach ( $available_gateways as $gateway_id => $gateway ) { + // Оставляем только выбранный способ оплаты + if ( $gateway_id !== $default_payment_gateway ) { + unset( $available_gateways[ $gateway_id ] ); + } + } + } + } + + return $available_gateways; +} + +add_filter( 'woocommerce_checkout_terms_and_conditions_checkbox_enabled', '__return_false' ); +add_filter( 'woocommerce_checkout_terms_is_required', '__return_false' ); +remove_action( 'woocommerce_checkout_before_terms_and_conditions', 'wc_checkout_privacy_policy_text', 20 ); +remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_terms_and_conditions_page_content', 30 ); +remove_action( 'woocommerce_checkout_after_terms_and_conditions', 'wc_privacy_policy_text', 20 ); + +add_action( 'woocommerce_checkout_process', 'remove_terms_validation' ); + +function remove_terms_validation() { + remove_action( 'woocommerce_checkout_process', 'woocommerce_checkout_terms_and_conditions' ); +} + +add_filter( 'woocommerce_order_button_html', 'custom_checkout_button_classes' ); + +function custom_checkout_button_classes( $button ) { + // Заменяем стандартные классы + $button = '
- ' . esc_html( $formatted_destination ) . '' ); - $calculator_text = esc_html__( 'Change address', 'woocommerce' ); - } else { - echo wp_kses_post( apply_filters( 'woocommerce_shipping_estimate_html', __( 'Shipping options will be updated during checkout.', 'woocommerce' ) ) ); - } - ?> -
- - -Нет доступных способов доставки. Для отображение доступных методов укажите ваш город.
- - - - - -