diff --git a/wp-content/themes/cosmopet/functions.php b/wp-content/themes/cosmopet/functions.php index f1347d6..9210656 100644 --- a/wp-content/themes/cosmopet/functions.php +++ b/wp-content/themes/cosmopet/functions.php @@ -425,6 +425,7 @@ require_once('modules/blog/module-ajax-controller.php'); require_once('modules/forms/module-ajax-controller.php'); require_once('modules/shop/module-ajax-controller.php'); + add_action('wp', 'my_custom_checkout_code'); function my_custom_checkout_code() { if (function_exists('is_checkout') && is_checkout() && !is_order_received_page()) { @@ -434,7 +435,6 @@ function my_custom_checkout_code() { require_once('modules/author/module-ajax-controller.php'); - include_module('forms'); include_module('layout'); diff --git a/wp-content/themes/cosmopet/global-functions/multilang-functions.php b/wp-content/themes/cosmopet/global-functions/multilang-functions.php index e69de29..161d7a7 100644 --- a/wp-content/themes/cosmopet/global-functions/multilang-functions.php +++ b/wp-content/themes/cosmopet/global-functions/multilang-functions.php @@ -0,0 +1,44 @@ + +скидку!', 'Узнайте о нас больше и получите скидку!'); + 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/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..bb96745 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,9 @@ 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 +29,8 @@ 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/module-ajax-controller.php b/wp-content/themes/cosmopet/modules/shop/module-ajax-controller.php index e69de29..7b8eb35 100644 --- a/wp-content/themes/cosmopet/modules/shop/module-ajax-controller.php +++ b/wp-content/themes/cosmopet/modules/shop/module-ajax-controller.php @@ -0,0 +1,143 @@ + 'Код купона не указан.' ) ); + } + + // Применение купона + $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 9c541f6..5fb6a26 100644 --- a/wp-content/themes/cosmopet/modules/shop/module-controller.php +++ b/wp-content/themes/cosmopet/modules/shop/module-controller.php @@ -1,5 +1,327 @@ '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 = '