Add cart and checkout

pull/14/head
gp_dev 3 months ago
parent 5225a200cf
commit fd51269523
  1. 3
      wp-content/themes/cosmopet/functions.php
  2. 43
      wp-content/themes/cosmopet/global-functions/multilang-functions.php
  3. 166
      wp-content/themes/cosmopet/modules/layout/assets/js/_gp-function.js
  4. 1
      wp-content/themes/cosmopet/modules/layout/module-controller.php
  5. 4
      wp-content/themes/cosmopet/modules/shop/components/cart/assets/js/cart.js
  6. 8
      wp-content/themes/cosmopet/modules/shop/components/cart/component-controller.php
  7. 143
      wp-content/themes/cosmopet/modules/shop/module-ajax-controller.php
  8. 323
      wp-content/themes/cosmopet/modules/shop/module-controller.php
  9. 26
      wp-content/themes/cosmopet/templates/layout.twig
  10. 29
      wp-content/themes/cosmopet/woocommerce/cart/cart-item-data.php
  11. 121
      wp-content/themes/cosmopet/woocommerce/cart/cart-shipping.php
  12. 236
      wp-content/themes/cosmopet/woocommerce/cart/cart.php
  13. 57
      wp-content/themes/cosmopet/woocommerce/cart/cross-sells.php
  14. 167
      wp-content/themes/cosmopet/woocommerce/cart/mini-cart.php

@ -595,4 +595,5 @@ register_sidebar( array(
) );
add_filter( 'woocommerce_price_trim_zeros', '__return_true' );
add_filter( 'woocommerce_price_trim_zeros', '__return_true' );

@ -0,0 +1,43 @@
<?php
add_action('init', function() {
pll_register_string ('Темы', 'Темы');
pll_register_string ('САМЫЕ ЧИТАЕМЫЕ', 'САМЫЕ ЧИТАЕМЫЕ');
pll_register_string ('время чтения', 'время чтения');
pll_register_string ('ВСЕ СТАТЬИ', 'ВСЕ СТАТЬИ');
pll_register_string ('ПРЕДЛОЖИТЕ СТАТЬЮ ИЛИ СТАНЬТЕ АВТОРОМ', 'ПРЕДЛОЖИТЕ СТАТЬЮ ИЛИ СТАНЬТЕ АВТОРОМ');
pll_register_string ('НАПИШИТЕ НАМ', 'НАПИШИТЕ НАМ');
pll_register_string ('COSMO тема редакции', 'COSMO тема редакции');
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 ('Подпишитесь, чтобы быть в курсе деятельности Cosmopet и узнавать о наших, предложениях. Обещаем не заваливать вас бесполезными письмами. А за подписку дарим -25% на весь ассортимент нашей продукции', 'Подпишитесь, чтобы быть в курсе деятельности Cosmopet и узнавать о наших предложениях. Обещаем не заваливать вас бесполезными письмами. А за подписку дарим -25% на весь ассортимент нашей продукции');
pll_register_string ('Подписываясь на рассылку, я даю согласие на обработку персональных данных, на получение рекламных сообщений и новостей о товарах и услугах', 'Подписываясь на рассылку, я даю согласие на обработку персональных данных, на получение рекламных сообщений и новостей о товарах и услугах');
pll_register_string ('подписаться', 'подписаться');
pll_register_string ('Узнайте о нас больше и получите <span>скидку!</span>', 'Узнайте о нас больше и получите <span>скидку!</span>');
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 ('ЭТАПЫ ПРОИЗВОД&shyСТВА', 'ЭТАПЫ ПРОИЗВОД&shyСТВА');
pll_register_string ('Этапы производс&shyтва корма', 'Этапы производс&shyтва корма');
pll_register_string ('Все статьи', 'Все статьи');
pll_register_string ('Узнать больше', 'Узнать больше');
});

@ -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

@ -3,4 +3,5 @@
include_module('header');
include_component('shop', 'cart');
include_module('shop');
include_module('footer');

@ -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');

@ -1,8 +0,0 @@
<?php
add_filter('woocommerce_get_script_data', 'add_custom_woocommerce_params', 10, 2);
function add_custom_woocommerce_params($params, $handle) {
// Добавляем только для скрипта корзины
$params['i18n_restore_item'] = pll__('Восстановить');
return $params;
}

@ -0,0 +1,143 @@
<?php
add_action( 'wp_ajax_apply_coupon', 'custom_apply_coupon' );
add_action( 'wp_ajax_nopriv_apply_coupon', 'custom_apply_coupon' );
function custom_apply_coupon() {
$coupon_code = isset( $_POST['coupon_code'] ) ? sanitize_text_field( $_POST['coupon_code'] ) : '';
if ( empty( $coupon_code ) ) {
wp_send_json_error( array( 'message' => 'Код купона не указан.' ) );
}
// Применение купона
$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('Не удалось удалить товар из корзины');
}
}

@ -0,0 +1,323 @@
<?php
add_filter( 'woocommerce_cart_needs_shipping_address', '__return_false' );
add_filter( 'woocommerce_shipping_calculator_enable_postcode', '__return_false' );
add_filter( 'woocommerce_shipping_calculator_enable_city', '__return_false' );
add_filter( 'woocommerce_shipping_calculator_enable_state', '__return_false' );
add_filter( 'woocommerce_shipping_packages', 'display_all_shipping_methods' );
function display_all_shipping_methods( $packages ) {
foreach ( $packages as &$package ) {
// Убираем ограничения по адресу
$package['destination']['country'] = '';
$package['destination']['state'] = '';
$package['destination']['postcode'] = '';
$package['destination']['city'] = '';
}
return $packages;
}
add_filter( 'woocommerce_checkout_fields', 'customize_billing_fields' );
function customize_billing_fields( $fields ) {
// Удаляем все стандартные поля
unset( $fields['billing']['billing_company'] );
unset( $fields['billing']['billing_country'] );
unset( $fields['billing']['billing_address_1'] );
unset( $fields['billing']['billing_address_2'] );
unset( $fields['billing']['billing_city'] );
unset( $fields['billing']['billing_state'] );
unset( $fields['billing']['billing_postcode'] );
// Перенастраиваем только нужные поля
$fields['billing']['billing_first_name'] = array(
'type' => '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 = '<div class="order-your-calculation__submit">
<button type="submit" class="button alt button--gradient button--high button--100-perc" name="woocommerce_checkout_place_order" id="place_order" value="Оплатить" data-value="Оплатить"><span>Оплатить</span></button>
</div>';
return $button;
}
add_filter( 'woocommerce_checkout_fields', 'customize_checkout_registration_fields' );
function customize_checkout_registration_fields( $fields ) {
// Убираем поле ввода пароля
unset( $fields['account']['account_password'] );
return $fields;
}
// Автоматическая генерация пароля
add_filter( 'woocommerce_checkout_posted_data', 'generate_password_for_registration' );
function generate_password_for_registration( $data ) {
$billing_first_name = isset( $_POST['billing_first_name'] ) ? sanitize_text_field( $_POST['billing_first_name'] ) : '';
$billing_last_name = isset( $_POST['billing_last_name'] ) ? sanitize_text_field( $_POST['billing_last_name'] ) : '';
$billing_address_1 = isset( $_POST['billing_address_1'] ) ? sanitize_text_field( $_POST['billing_address_1'] ) : '';
$billing_address_2 = isset( $_POST['billing_address_2'] ) ? sanitize_text_field( $_POST['billing_address_2'] ) : '';
$billing_city = isset( $_POST['billing_city'] ) ? sanitize_text_field( $_POST['billing_city'] ) : '';
$billing_postcode = isset( $_POST['billing_postcode'] ) ? sanitize_text_field( $_POST['billing_postcode'] ) : '';
$billing_country = isset( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : '';
$billing_state = isset( $_POST['billing_state'] ) ? sanitize_text_field( $_POST['billing_state'] ) : '';
$billing_phone = isset( $_POST['billing_phone'] ) ? sanitize_text_field( $_POST['billing_phone'] ) : '';
$billing_email = isset( $_POST['billing_email'] ) ? sanitize_email( $_POST['billing_email'] ) : '';
$data['shipping_first_name'] = $data['billing_first_name'];
$data['shipping_last_name'] = $data['billing_last_name'];
$data['shipping_address_1'] = $data['billing_address_1'] . $data['billing_address_2'];
$data['shipping_city'] = $data['billing_city'];
$data['shipping_postcode'] = $data['billing_postcode'];
$data['shipping_country'] = $data['billing_country'];
$data['shipping_state'] = $data['billing_state'];
return $data;
}
function handle_user_registration_on_checkout() {
// Получаем данные из POST-запроса
if ( isset( $_POST['billing_email'] ) && isset( $_POST['reg'] )) {
if ($_POST['reg'] == '1'){
$email = sanitize_email( $_POST['billing_email'] );
$pass = sanitize_text_field( $_POST['pass'] );
// Регистрация пользователя
$user_id = custom_register_user_from_post( $email, $pass );
if ( is_wp_error( $user_id ) ) {
// Если email уже существует, выводим ошибку
wc_add_notice( $user_id->get_error_message(), 'error' );
} else {
wp_set_current_user( $user_id ); // Устанавливаем текущего пользователя
wp_set_auth_cookie( $user_id ); // Устанавливаем куки для авторизации
do_action( 'wp_login', $email, $user ); // Событие входа в систему
}}
}
}
add_action( 'woocommerce_checkout_process', 'handle_user_registration_on_checkout' );
function custom_register_user_from_post( $email, $pass ) {
// Проверяем, есть ли уже пользователь с таким email
if ( email_exists( $email ) ) {
return new WP_Error( 'email_exists', 'Этот email уже зарегистрирован.' );
}
// Создаем пользователя в WordPress
$user_id = wp_create_user( $email, $pass, $email );
if ( is_wp_error( $user_id ) ) {
return $user_id; // Возвращаем ошибку, если не удалось создать пользователя
}
update_user_meta( $user_id, 'billing_email', $email ); // Устанавливаем email
update_user_meta( $user_id, 'user_email', $email ); // Устанавливаем email для входа
// Устанавливаем роль пользователя как 'customer' для WooCommerce
$user = new WP_User( $user_id );
$user->set_role( 'customer' );
return $user_id;
}
add_filter( 'woocommerce_form_field', 'add_error_containers_to_checkout_fields', 10, 4 );
function add_error_containers_to_checkout_fields( $field, $key, $args, $value ) {
if ( is_checkout() ) {
// Добавляем контейнер для ошибок под полем
$error_container = '<div id="' . esc_attr( $key ) . '-error" class="form-input__error"></div>';
$field .= $error_container;
}
return $field;
}
add_filter( 'woocommerce_add_error', 'remove_payments_word_from_errors_multilang' );
function remove_payments_word_from_errors_multilang( $error ) {
// Слова для удаления в разных языках
$translations = array(
'Платежи', // Русский
'Billing', // Английский
);
foreach ( $translations as $word ) {
$error = str_replace( $word, '', $error );
}
return trim( $error );
}
add_action( 'woocommerce_checkout_process', 'validate_phone_field_with_li_data_id' );
function validate_phone_field_with_li_data_id() {
// Получаем значение телефона из формы
$phone = isset( $_POST['billing_phone'] ) ? sanitize_text_field( $_POST['billing_phone'] ) : '';
// Проверяем формат телефона
if ( ! preg_match( '/^\+?[0-9\s\-\(\)]+$/', $phone ) ) {
wc_add_notice( 'phone_err', 'error', 'billing_phone' );
}
}
add_action( 'woocommerce_checkout_process', 'make_address_required_for_specific_shipping' );
function make_address_required_for_specific_shipping() {
// Получаем выбранный метод доставки
$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = isset( $chosen_shipping_methods[0] ) ? $chosen_shipping_methods[0] : '';
// Проверяем, выбран ли метод доставки "official_cdek:137"
if ( $chosen_shipping === 'official_cdek:137' ) {
// Проверяем, заполнен ли адрес
if ( empty( $_POST['billing_address_1'] ) ) {
wc_add_notice('adress_error', 'error' );
}
}
}
function auto_fill_shipping_fields_from_billing( $order_id ) {
// Получаем объект заказа
$order = wc_get_order( $order_id );
if ( ! $order ) {
return; // Если заказ недоступен, выходим
}
// Получаем значения полей billing из глобального $_POST
$billing_first_name = isset( $_POST['billing_first_name'] ) ? sanitize_text_field( $_POST['billing_first_name'] ) : '';
$billing_last_name = isset( $_POST['billing_last_name'] ) ? sanitize_text_field( $_POST['billing_last_name'] ) : '';
$billing_address_1 = isset( $_POST['billing_address_1'] ) ? sanitize_text_field( $_POST['billing_address_1'] ) : '';
$billing_address_2 = isset( $_POST['billing_address_2'] ) ? sanitize_text_field( $_POST['billing_address_2'] ) : '';
$billing_city = isset( $_POST['billing_city'] ) ? sanitize_text_field( $_POST['billing_city'] ) : '';
$billing_postcode = isset( $_POST['billing_postcode'] ) ? sanitize_text_field( $_POST['billing_postcode'] ) : '';
$billing_country = isset( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : '';
$billing_state = isset( $_POST['billing_state'] ) ? sanitize_text_field( $_POST['billing_state'] ) : '';
$billing_phone = isset( $_POST['billing_phone'] ) ? sanitize_text_field( $_POST['billing_phone'] ) : '';
$billing_email = isset( $_POST['billing_email'] ) ? sanitize_email( $_POST['billing_email'] ) : '';
// Копируем данные в поля доставки
$order->set_shipping_first_name( $billing_first_name );
$order->set_shipping_last_name( $billing_last_name );
$order->set_shipping_address_1( $billing_address_1 );
$order->set_shipping_address_2( $billing_address_2 );
$order->set_shipping_city( $billing_city );
$order->set_shipping_postcode( $billing_postcode );
$order->set_shipping_country( $billing_country );
$order->set_shipping_state( $billing_state );
// Сохраняем изменения в заказе
$order->save();
}

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="ru">
<head>
{{ function('wp_head') }}
<title>{{ function('wp_title') }} </title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body class="{{bodyClass}}">
{% include 'header.twig' %}
<main class="{{ mainClass }}">
{% block content %}
{% endblock %}
{% include 'modal.twig' %}
</main>
{% include 'footer.twig' %}
</div>
{{ function('wp_footer') }}
</body>
</html>

@ -1,29 +0,0 @@
<?php
/**
* Cart item data (when outputting non-flat)
*
* This template can be overridden by copying it to yourtheme/woocommerce/cart/cart-item-data.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.4.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<ul class="variation">
<?php foreach ( $item_data as $data ) : ?>
<li class="variation-<?php echo sanitize_html_class( $data['key'] ); ?>">
<span class="item-variation-name"><?php echo wp_kses_post( $data['key'] ); ?>:</span>
<span class="item-variation-value"><?php echo wp_kses_post( wpautop( $data['display'] ) ); ?></span>
</li>
<?php endforeach; ?>
</ul>

@ -1,121 +0,0 @@
<?php
/**
* Shipping Methods Display
*
* In 2.1 we show methods per package. This allows for multiple methods per order if so desired.
*
* This template can be overridden by copying it to yourtheme/woocommerce/cart/cart-shipping.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
* @version 8.8.0
*/
defined( 'ABSPATH' ) || exit;
$formatted_destination = isset( $formatted_destination ) ? $formatted_destination : WC()->countries->get_formatted_address( $package['destination'], ', ' );
$has_calculated_shipping = ! empty( $has_calculated_shipping );
$show_shipping_calculator = ! empty( $show_shipping_calculator );
$calculator_text = '';
?>
<tr class="woocommerce-shipping-totals shipping">
<?php
?>
<td data-title="<?php echo esc_attr( $package_name ); ?>" class="modal-map__control modal-map__control--delivery">
<?php if ( ! empty( $available_methods ) && is_array( $available_methods ) ) : ?>
<ul id="shipping_method" class="woocommerce-shipping-methods">
<?php foreach ( $available_methods as $method ) :
$pattern = '/^(.*?),\s*\((.*?)\)$/';
if (preg_match($pattern, $method->label, $matches)) {
$text_before_comma = trim($matches[1]); // Текст до запятой
$text_in_parentheses = trim($matches[2]); // Текст в скобках
} else {
$text_before_comma = '';
$text_in_parentheses = '';
}
if ($text_before_comma == 'CDEK: Посылка склад-дверь'){
$title = 'Курьером';
}
else if ($text_before_comma == 'CDEK: Посылка склад-склад'){
$title = 'Пункт выдачи';
}
?>
<li data-remote="<?php echo $method->id ?>" class="modal-map-control__item <?php if ($method->id == $chosen_method): ?>active <?php endif; ?>">
<label>
<div class="modal-map-control-item__content">
<div class="modal-map-control-item__header">
<div class="modal-map-control-item__circle"><div class="modal-map-control-item-circle__content"></div></div>
<p class="modal-map-control-item__title">
<?php
echo $title;
?>
</p>
</div>
<div class="modal-map-control-item__description">
<p class="modal-map-control-item__time"><?php echo $text_in_parentheses; ?></p>
<p class="modal-map-control-item__price"> <?php
echo $method->cost;
?>₽</p>
</div>
<?php do_action( 'woocommerce_after_shipping_rate', $method, $index ); ?>
</div>
<?php
if ( 1 < count( $available_methods ) ) {
printf( '<input type="radio" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d_%2$s" value="%3$s" class="shipping_method visually-hidden" %4$s />', $index, esc_attr( sanitize_title( $method->id ) ), esc_attr( $method->id ), checked( $method->id, $chosen_method, false ) ); // WPCS: XSS ok.
} else {
printf( '<input type="hidden" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d_%2$s" value="%3$s" class="shipping_method visually-hidden" />', $index, esc_attr( sanitize_title( $method->id ) ), esc_attr( $method->id ) ); // WPCS: XSS ok.
}
?>
</label>
</li>
<?php endforeach; ?>
<?php
?>
</ul>
<?php if ( is_cart() ) : ?>
<p class="woocommerce-shipping-destination">
<?php
if ( $formatted_destination ) {
// Translators: $s shipping destination.
printf( esc_html__( 'Shipping to %s.', 'woocommerce' ) . ' ', '<strong>' . esc_html( $formatted_destination ) . '</strong>' );
$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' ) ) );
}
?>
</p>
<?php endif; ?>
<?php
else:
?>
<p> Нет доступных способов доставки. Для отображение доступных методов укажите ваш город.</p>
<?php
endif;
?>
</td>
</tr>
<style>
</style>

@ -1,236 +0,0 @@
<?php
/**
* Cart Page
*
* This template can be overridden by copying it to yourtheme/woocommerce/cart/cart.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @version 7.9.0
*/
wp_enqueue_style( 'gp-cart', get_template_directory_uri() . '/gp-include/assets/front-page/css/gp-cart.css' );
defined( 'ABSPATH' ) || exit;
$update_cart_btn_classes = '';
if ( function_exists( 'wc_wp_theme_get_element_class_name' ) ) {
$update_cart_btn_classes .= ' ' . wc_wp_theme_get_element_class_name( 'button' );
}
if ( woodmart_get_opt( 'update_cart_quantity_change' ) ) {
$update_cart_btn_classes .= ' wd-hide';
}
?>
<div class="woocommerce cart-content-wrapper row">
<?php do_action( 'woocommerce_before_cart' ); ?>
<form class="woocommerce-cart-form cart-data-form col-12 col-lg-7 col-xl-8" action="<?php echo esc_url( wc_get_cart_url() ); ?>" method="post">
<div class="cart-table-section">
<?php do_action( 'woocommerce_before_cart_table' ); ?>
<table class="shop_table shop_table_responsive cart woocommerce-cart-form__contents" cellspacing="0">
<thead>
<tr>
<th class="product-remove"><span class="screen-reader-text"><?php esc_html_e( 'Remove item', 'woocommerce' ); ?></span></th>
<th class="product-thumbnail"><span class="screen-reader-text"><?php esc_html_e( 'Thumbnail image', 'woocommerce' ); ?></span>;</th>
<th class="product-name"><?php esc_html_e( 'Product', 'woocommerce' ); ?></th>
<?php if ( woodmart_get_opt( 'show_sku_in_cart' ) ) : ?>
<th class="product-sku"><?php esc_html_e( 'SKU', 'woocommerce' ); ?></th>
<?php endif; ?>
<th class="product-price"><?php esc_html_e( 'Price', 'woocommerce' ); ?></th>
<th class="product-quantity"><?php esc_html_e( 'Quantity', 'woocommerce' ); ?></th>
<th class="product-subtotal"><?php esc_html_e( 'Subtotal', 'woocommerce' ); ?></th>
</tr>
</thead>
<tbody>
<?php do_action( 'woocommerce_before_cart_contents' ); ?>
<?php
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
$product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
$product_permalink = apply_filters( 'woocommerce_cart_item_permalink', $_product->is_visible() ? $_product->get_permalink( $cart_item ) : '', $cart_item, $cart_item_key );
$product_name = apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key );
?>
<tr class="woocommerce-cart-form__cart-item <?php echo esc_attr( apply_filters( 'woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key ) ); ?>">
<td class="product-remove">
<?php
echo apply_filters( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
'woocommerce_cart_item_remove_link',
sprintf(
'<a href="%s" class="remove" aria-label="%s" data-product_id="%s" data-product_sku="%s">&times;</a>',
esc_url( wc_get_cart_remove_url( $cart_item_key ) ),
/* translators: %s is the product name */
esc_attr( sprintf( __( 'Remove %s from cart', 'woocommerce' ), wp_strip_all_tags( $product_name ) ) ),
esc_attr( $product_id ),
esc_attr( $_product->get_sku() )
),
$cart_item_key
);
?>
</td>
<td class="product-thumbnail">
<?php
if ( ! $product_permalink ) {
echo apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key );
} else {
printf( '<a href="%s">%s</a>', esc_url( $product_permalink ), apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key ) );
}
?>
</td>
<td class="product-name" data-title="<?php esc_attr_e( 'Product', 'woocommerce' ); ?>">
<?php
if ( ! $product_permalink ) {
echo wp_kses_post( $product_name . '&nbsp;' );
} else {
/**
* This filter is documented above.
*
* @since 7.8.0
* @param string $product_url URL the product in the cart.
*/
echo wp_kses_post( apply_filters( 'woocommerce_cart_item_name', sprintf( '<a href="%s">%s</a>', esc_url( $product_permalink ), $_product->get_name() ), $cart_item, $cart_item_key ) );
}
do_action( 'woocommerce_after_cart_item_name', $cart_item, $cart_item_key );
// Meta data
echo wc_get_formatted_cart_item_data( $cart_item );
// Backorder notification
if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $cart_item['quantity'] ) ) {
echo wp_kses_post( apply_filters( 'woocommerce_cart_item_backorder_notification', '<p class="backorder_notification">' . esc_html__( 'Available on backorder', 'woocommerce' ) . '</p>', $product_id ) );
}
?>
</td>
<?php if ( woodmart_get_opt( 'show_sku_in_cart' ) ) : ?>
<td class="product-sku" data-title="<?php esc_attr_e( 'SKU', 'woocommerce' ); ?>">
<?php if ( $_product->get_sku() ) : ?>
<?php echo esc_html( $_product->get_sku() ); ?>
<?php else : ?>
<?php esc_html_e( 'N/A', 'woocommerce' ); ?>
<?php endif; ?>
</td>
<?php endif; ?>
<td class="product-price" data-title="<?php esc_attr_e( 'Price', 'woocommerce' ); ?>">
<?php
echo apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key );
?>
</td>
<td class="product-quantity" data-title="<?php esc_attr_e( 'Quantity', 'woocommerce' ); ?>">
<?php
if ( $_product->is_sold_individually() ) {
$min_quantity = 1;
$max_quantity = 1;
} else {
$min_quantity = 0;
$max_quantity = $_product->get_max_purchase_quantity();
}
$product_quantity = woocommerce_quantity_input(
array(
'input_name' => "cart[{$cart_item_key}][qty]",
'input_value' => $cart_item['quantity'],
'max_value' => $max_quantity,
'min_value' => $min_quantity,
'product_name' => $product_name,
),
$_product,
false
);
echo apply_filters( 'woocommerce_cart_item_quantity', $product_quantity, $cart_item_key, $cart_item );
?>
</td>
<td class="product-subtotal" data-title="<?php esc_attr_e( 'Subtotal', 'woocommerce' ); ?>">
<?php
echo apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal( $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key );
?>
</td>
</tr>
<?php
}
}
?>
<?php do_action( 'woocommerce_cart_contents' ); ?>
<?php do_action( 'woocommerce_after_cart_contents' ); ?>
</tbody>
</table>
<div class="row cart-actions">
<div class="col-12 order-last order-md-first col-md">
<?php if ( wc_coupons_enabled() ) { ?>
<div class="coupon">
<label for="coupon_code" class="screen-reader-text">
<?php esc_html_e( 'Coupon:', 'woocommerce' ); ?>
</label>
<input type="text" name="coupon_code" class="input-text" id="coupon_code" value="" placeholder="<?php esc_attr_e( 'Coupon code', 'woocommerce' ); ?>" />
<button type="submit" class="button<?php echo esc_attr( function_exists( 'wc_wp_theme_get_element_class_name' ) && wc_wp_theme_get_element_class_name( 'button' ) ? ' ' . wc_wp_theme_get_element_class_name( 'button' ) : '' ); ?>" name="apply_coupon" value="<?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?>">
<?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?>
</button>
<?php do_action( 'woocommerce_cart_coupon' ); ?>
</div>
<?php } ?>
</div>
<div class="col-12 order-first order-md-last col-md-auto">
<button type="submit" class="button<?php echo esc_attr( $update_cart_btn_classes ); ?>" name="update_cart" value="<?php esc_attr_e( 'Update cart', 'woocommerce' ); ?>">
<?php esc_html_e( 'Update cart', 'woocommerce' ); ?>
</button>
<?php do_action( 'woocommerce_cart_actions' ); ?>
<?php wp_nonce_field( 'woocommerce-cart', 'woocommerce-cart-nonce' ); ?>
</div>
</div>
</div>
</form>
<div class="cart-totals-section col-12 col-lg-5 col-xl-4 cart-collaterals">
<?php woocommerce_cart_totals(); ?>
</div>
</div>
<?php do_action( 'woocommerce_after_cart_table' ); ?>
<div class="cart-collaterals">
<?php
/**
* Cart collaterals hook.
*
* @hooked woocommerce_cross_sell_display
* @hooked woocommerce_cart_totals - 10
*/
do_action( 'woocommerce_cart_collaterals' );
?>
</div>
<?php do_action( 'woocommerce_after_cart' ); ?>

@ -1,57 +0,0 @@
<?php
/**
* Cross-sells
*
* This template can be overridden by copying it to yourtheme/woocommerce/cart/cross-sells.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @version 4.4.0
*/
defined( 'ABSPATH' ) || exit;
$heading = apply_filters( 'woocommerce_product_cross_sells_products_heading', __( 'You may be interested in&hellip;', 'woocommerce' ) );
if ( $cross_sells ) : ?>
<div class="cross-sells">
<?php if ( $heading ) : ?>
<h3 class="title slider-title"><span><?php echo esc_html( $heading ); ?></span></h3>
<?php endif; ?>
<?php
woodmart_enqueue_product_loop_styles( woodmart_get_opt( 'products_hover' ) );
$slider_args = array(
'slides_per_view' => apply_filters( 'woodmart_cross_sells_products_per_view', 4 ),
'hide_pagination_control' => true,
'hide_prev_next_buttons' => true,
'img_size' => 'woocommerce_thumbnail',
'custom_sizes' => apply_filters( 'woodmart_cross_sells_custom_sizes', false ),
'product_quantity' => woodmart_get_opt( 'product_quantity' ),
'products_bordered_grid' => woodmart_get_opt( 'products_bordered_grid' ),
'products_bordered_grid_style' => woodmart_get_opt( 'products_bordered_grid_style' ),
'products_with_background' => woodmart_get_opt( 'products_with_background' ),
'products_shadow' => woodmart_get_opt( 'products_shadow' ),
'products_color_scheme' => woodmart_get_opt( 'products_color_scheme' ),
);
woodmart_set_loop_prop( 'products_view', 'carousel' );
echo woodmart_generate_posts_slider( $slider_args, false, $cross_sells );
?>
</div>
<?php endif;
wp_reset_postdata();

@ -1,167 +0,0 @@
<?php
/**
* Mini-cart
*
* Contains the markup for the mini-cart, used by the cart widget.
*
* This template can be overridden by copying it to yourtheme/woocommerce/cart/mini-cart.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
* @version 7.9.0
*/
defined( 'ABSPATH' ) || exit;
$items_to_show = apply_filters( 'woodmart_mini_cart_items_to_show', 30 );
do_action( 'woocommerce_before_mini_cart' ); ?>
<div class="shopping-cart-widget-body wd-scroll">
<div class="wd-scroll-content">
<?php if ( ! WC()->cart->is_empty() ) : ?>
<ul class="cart_list product_list_widget woocommerce-mini-cart <?php echo esc_attr( $args['list_class'] ); ?>">
<?php
do_action( 'woocommerce_before_mini_cart_contents' );
$_i = 0;
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$_i++;
if( $_i > $items_to_show ) break;
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
$product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_widget_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
/**
* This filter is documented in woocommerce/templates/cart/cart.php.
*
* @param string $product_name Name of the product in the cart.
*/
$product_name = apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key );
$product_price = apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key );
$product_permalink = apply_filters( 'woocommerce_cart_item_permalink', $_product->is_visible() ? $_product->get_permalink( $cart_item ) : '', $cart_item, $cart_item_key );
?>
<li class="woocommerce-mini-cart-item <?php echo esc_attr( apply_filters( 'woocommerce_mini_cart_item_class', 'mini_cart_item', $cart_item, $cart_item_key ) ); ?>" data-key="<?php echo esc_attr( $cart_item_key ); ?>">
<a href="<?php echo esc_url( $product_permalink ); ?>" class="cart-item-link wd-fill"><?php esc_html_e('Show', 'woocommerce'); ?></a>
<?php
echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf(
'<a href="%s" class="remove remove_from_cart_button" aria-label="%s" data-product_id="%s" data-cart_item_key="%s" data-product_sku="%s">&times;</a>',
esc_url( wc_get_cart_remove_url( $cart_item_key ) ),
/* translators: %s is the product name */
esc_attr( sprintf( __( 'Remove %s from cart', 'woocommerce' ), wp_strip_all_tags( $product_name ) ) ),
esc_attr( $product_id ),
esc_attr( $cart_item_key ),
esc_attr( $_product->get_sku() )
), $cart_item_key );
?>
<?php if ( empty( $product_permalink ) ) : ?>
<?php echo apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key ); ?>
<?php else : ?>
<a href="<?php echo esc_url( $product_permalink ); ?>" class="cart-item-image">
<?php echo apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key ); ?>
</a>
<?php endif; ?>
<div class="cart-info">
<span class="wd-entities-title">
<?php echo $product_name; ?>
</span>
<?php if ( woodmart_get_opt( 'show_sku_in_mini_cart' ) ) : ?>
<div class="wd-product-sku">
<span class="wd-label">
<?php esc_html_e( 'SKU:', 'woodmart' ); ?>
</span>
<span>
<?php if ( $_product->get_sku() ) : ?>
<?php echo esc_html( $_product->get_sku() ); ?>
<?php else : ?>
<?php esc_html_e( 'N/A', 'woocommerce' ); ?>
<?php endif; ?>
</span>
</div>
<?php endif; ?>
<?php
echo wc_get_formatted_cart_item_data( $cart_item );
?>
<?php
if ( ! $_product->is_sold_individually() && $_product->is_purchasable() && woodmart_get_opt( 'mini_cart_quantity' ) && apply_filters( 'woodmart_show_widget_cart_item_quantity', true, $cart_item_key ) ) {
woocommerce_quantity_input(
array(
'input_value' => $cart_item['quantity'],
'min_value' => 0,
'max_value' => $_product->backorders_allowed() ? '' : $_product->get_stock_quantity(),
),
$_product
);
}
?>
<?php echo apply_filters( 'woocommerce_widget_cart_item_quantity', '<span class="quantity">' . sprintf( '%s &times; %s', $cart_item['quantity'], $product_price ) . '</span>', $cart_item, $cart_item_key ); ?>
</div>
</li>
<?php
}
}
do_action( 'woocommerce_mini_cart_contents' );
?>
</ul><!-- end product list -->
<?php else : ?>
<div class="wd-empty-mini-cart">
<p class="woocommerce-mini-cart__empty-message empty title"><?php esc_html_e( 'No products in the cart.', 'woocommerce' ); ?></p>
<?php if ( wc_get_page_id( 'shop' ) > 0 ) : ?>
<a class="btn btn-size-small btn-color-primary wc-backward" href="<?php echo esc_url( apply_filters( 'woocommerce_return_to_shop_redirect', wc_get_page_permalink( 'shop' ) ) ); ?>">
<?php esc_html_e( 'Return To Shop', 'woodmart' ) ?>
</a>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
</div>
<div class="shopping-cart-widget-footer<?php echo ( WC()->cart->is_empty() ? ' wd-cart-empty' : '' ); ?>">
<?php if ( ! WC()->cart->is_empty() ) : ?>
<?php if ( function_exists( 'WC' ) && version_compare( WC()->version, '3.7.0', '<' ) ) : ?>
<p class="woocommerce-mini-cart__total total"><strong><?php esc_html_e( 'Subtotal', 'woocommerce' ); ?>:</strong> <?php echo WC()->cart->get_cart_subtotal(); ?></p>
<?php else : ?>
<p class="woocommerce-mini-cart__total total">
<?php
/**
* Woocommerce_widget_shopping_cart_total hook.
*
* @hooked woocommerce_widget_shopping_cart_subtotal - 10
*/
do_action( 'woocommerce_widget_shopping_cart_total' );
?>
</p>
<?php endif; ?>
<?php do_action( 'woocommerce_widget_shopping_cart_before_buttons' ); ?>
<p class="woocommerce-mini-cart__buttons buttons"><?php do_action( 'woocommerce_widget_shopping_cart_buttons' ); ?></p>
<?php do_action( 'woocommerce_widget_shopping_cart_after_buttons' ); ?>
<?php endif; ?>
<?php do_action( 'woocommerce_after_mini_cart' ); ?>
</div>
Loading…
Cancel
Save