Custom WooCommerce theme for orgsteklo.ru including: - Product catalog with category/subcategory hierarchy - Custom checkout with delivery calculation - Price calculator - Admin settings panel - Search functionality - User account pages
588 lines
30 KiB
PHP
588 lines
30 KiB
PHP
<?php
|
||
defined( 'ABSPATH' ) || exit;
|
||
do_action( 'woocommerce_before_cart' );
|
||
?>
|
||
<section class="cart">
|
||
<div class="cart-container container">
|
||
<h1>Корзина</h1>
|
||
<div class="cart-main">
|
||
<div class="cart-left">
|
||
<div class="cart-top">
|
||
<div class="cart-checkbox__all">
|
||
<input type="checkbox" id="cart-checkbox__all" name="cart-checkbox__all">
|
||
<label for="cart-checkbox__all">Выбрать все</label>
|
||
</div>
|
||
<button class="cart-delete-all">
|
||
Удалить выбранное
|
||
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M6.46875 13.5356L13.5398 6.46458" stroke="#F02E13" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M13.5398 13.5354L6.46875 6.46436" stroke="#F02E13" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
|
||
</button>
|
||
</div>
|
||
<form class="woocommerce-cart-form" action="<?php echo esc_url( wc_get_cart_url() ); ?>" method="post">
|
||
<input type="hidden" name="update_checkout_cart" value="1">
|
||
<?php do_action( 'woocommerce_before_cart_table' ); ?>
|
||
<div class="cart-products">
|
||
<?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 );
|
||
|
||
// Получаем название товара без вариаций
|
||
$product_name = $_product->get_name();
|
||
if ( $_product->is_type('variation') ) {
|
||
$parent_product = wc_get_product( $cart_item['product_id'] );
|
||
if ( $parent_product ) {
|
||
$product_name = $parent_product->get_name();
|
||
}
|
||
}
|
||
$product_name = apply_filters( 'woocommerce_cart_item_name', $product_name, $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 );
|
||
?>
|
||
<?php
|
||
$sku = $_product->get_sku();
|
||
$weight = $_product->get_weight();
|
||
$qty = $cart_item['quantity'];
|
||
$price = $_product->get_price();
|
||
$regular_price = $_product->get_regular_price();
|
||
$sale_price = $_product->get_sale_price();
|
||
$total_price = $price * $qty;
|
||
$total_regular_price = $regular_price * $qty;
|
||
$total_weight = $weight * $qty;
|
||
?>
|
||
<div class="cart-product">
|
||
<div class="cart-product__checkbox">
|
||
<input
|
||
type="checkbox"
|
||
data-cart_item_key="<?php echo esc_attr($cart_item_key); ?>"
|
||
name="cart_product_keys[]"
|
||
value="<?php echo esc_attr($cart_item_key); ?>"
|
||
id="cart-product__checkbox-<?php echo esc_attr($cart_item_key); ?>"
|
||
>
|
||
</div>
|
||
<?php
|
||
$thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key );
|
||
if ( ! $product_permalink ) {
|
||
echo $thumbnail;
|
||
}
|
||
else {
|
||
printf( '<a href="%s" class="cart-product__img">%s</a>', esc_url( $product_permalink ), $thumbnail ); // PHPCS: XSS ok.
|
||
}
|
||
?>
|
||
<div class="cart-product__main">
|
||
<div class="cart-product__col">
|
||
<div class="cart-product__sku">
|
||
<p>Код товара:</p>
|
||
<p><?php echo esc_html($sku); ?></p>
|
||
</div>
|
||
<a href="<?php echo esc_url($product_permalink); ?>" class="cart-product__title"><?php echo esc_html($product_name); ?></a>
|
||
<?php
|
||
// Отображаем параметры заказа для разных типов товаров
|
||
if ( isset( $cart_item['orgsteklo_calculator'] ) ) {
|
||
// Для товаров с калькулятором (оргстекло)
|
||
$calc = $cart_item['orgsteklo_calculator'];
|
||
echo '<div class="cart-product__params">';
|
||
echo '<p>Толщина: <strong>' . esc_html( $calc['thickness'] ) . ' мм</strong></p>';
|
||
echo '<p>Ширина: <strong>' . esc_html( $calc['width'] ) . ' мм</strong></p>';
|
||
echo '<p>Длина: <strong>' . esc_html( $calc['length'] ) . ' мм</strong></p>';
|
||
// Итоговая цена за 1 лист после Длины
|
||
echo '<p>Итоговая цена за 1 лист: <strong>' . wc_price($price) . '</strong>';
|
||
if ($regular_price > $price) {
|
||
echo ' <span style="text-decoration: line-through; color: #999;">' . wc_price($regular_price) . '</span>';
|
||
}
|
||
echo '</p>';
|
||
echo '</div>';
|
||
} elseif ( $_product->is_type('variation') ) {
|
||
$variation = wc_get_product( $cart_item['variation_id'] );
|
||
if ( $variation ) {
|
||
// Проверяем ширину и длину для определения листового материала
|
||
$width_meta = get_post_meta( $cart_item['variation_id'], '_variation_width', true );
|
||
if ( empty( $width_meta ) ) {
|
||
$width_meta = $variation->get_width();
|
||
}
|
||
$length_meta = get_post_meta( $cart_item['variation_id'], '_variation_length', true );
|
||
if ( empty( $length_meta ) ) {
|
||
$length_meta = $variation->get_length();
|
||
}
|
||
|
||
if ( $width_meta && $length_meta ) {
|
||
// Листовые материалы — отображение как у оргстекла
|
||
$attributes = $variation->get_variation_attributes();
|
||
$thickness_value = '';
|
||
foreach ( $attributes as $attr_key => $attr_value ) {
|
||
$attr_slug = str_replace( 'attribute_pa_', '', $attr_key );
|
||
$attr_slug = str_replace( 'attribute_', '', $attr_slug );
|
||
if ( stripos( $attr_slug, 'ves' ) !== false ) {
|
||
continue;
|
||
}
|
||
$taxonomy_name = str_replace( 'attribute_', '', $attr_key );
|
||
$term = get_term_by( 'slug', $attr_value, $taxonomy_name );
|
||
$thickness_value = $term ? $term->name : $attr_value;
|
||
break;
|
||
}
|
||
echo '<div class="cart-product__params">';
|
||
if ( $thickness_value ) {
|
||
$thickness_clean = preg_replace( '/\s*мм\s*$/u', '', $thickness_value );
|
||
$thickness_clean = preg_replace( '/\s*mm\s*$/i', '', $thickness_clean );
|
||
echo '<p>Толщина: <strong>' . esc_html( trim( $thickness_clean ) ) . ' мм</strong></p>';
|
||
}
|
||
echo '<p>Ширина: <strong>' . esc_html( $width_meta ) . ' мм</strong></p>';
|
||
echo '<p>Длина: <strong>' . esc_html( $length_meta ) . ' мм</strong></p>';
|
||
echo '</div>';
|
||
} else {
|
||
// Для остальных вариативных товаров (трубы/стержни/клей)
|
||
$attributes = $variation->get_variation_attributes();
|
||
$has_params = false;
|
||
$params_html = '';
|
||
foreach ( $attributes as $attr_key => $attr_value ) {
|
||
$attr_slug = str_replace( 'attribute_pa_', '', $attr_key );
|
||
$attr_slug = str_replace( 'attribute_', '', $attr_slug );
|
||
if ( $attr_slug === 'ves' || $attr_slug === 'pa_ves' || stripos( $attr_slug, 'ves' ) !== false ) {
|
||
continue;
|
||
}
|
||
$taxonomy_name = str_replace( 'attribute_', '', $attr_key );
|
||
$attr_name = '';
|
||
$attr_slug_clean = str_replace( 'pa_', '', $taxonomy_name );
|
||
$all_attr_taxonomies = wc_get_attribute_taxonomies();
|
||
foreach ( $all_attr_taxonomies as $tax ) {
|
||
if ( $tax->attribute_name === $attr_slug_clean ) {
|
||
$attr_name = $tax->attribute_label;
|
||
break;
|
||
}
|
||
}
|
||
if ( empty( $attr_name ) ) {
|
||
$best_label = '';
|
||
$best_dist = PHP_INT_MAX;
|
||
foreach ( $all_attr_taxonomies as $tax ) {
|
||
$dist = levenshtein( $attr_slug_clean, $tax->attribute_name );
|
||
if ( $dist < $best_dist && $dist <= 3 ) {
|
||
$best_dist = $dist;
|
||
$best_label = $tax->attribute_label;
|
||
}
|
||
}
|
||
if ( ! empty( $best_label ) ) {
|
||
$attr_name = $best_label;
|
||
}
|
||
}
|
||
if ( empty( $attr_name ) ) {
|
||
$attr_name = wc_attribute_label( $taxonomy_name );
|
||
}
|
||
$term = get_term_by( 'slug', $attr_value, $taxonomy_name );
|
||
$attr_value_display = $term ? $term->name : $attr_value;
|
||
$attr_value_display = str_replace( array( ' mm', 'mm' ), ' мм', $attr_value_display );
|
||
$params_html .= '<p>' . esc_html( $attr_name ) . ': <strong style="color: var(--Black);">' . esc_html( $attr_value_display ) . '</strong></p>';
|
||
$has_params = true;
|
||
}
|
||
$length_only = get_post_meta( $cart_item['variation_id'], '_variation_length', true );
|
||
if ( empty( $length_only ) ) {
|
||
$length_only = $variation->get_length();
|
||
}
|
||
if ( $length_only ) {
|
||
$params_html .= '<p>Длина: <strong style="color: var(--Black);">' . esc_html( $length_only ) . ' мм</strong></p>';
|
||
$has_params = true;
|
||
}
|
||
if ( $has_params ) {
|
||
echo '<div class="cart-product__params">' . $params_html . '</div>';
|
||
}
|
||
}
|
||
}
|
||
}
|
||
// Для простых товаров (клей) - НЕ показываем вес здесь, он уже есть в cart-product__chars
|
||
?>
|
||
<div class="cart-product__chars">
|
||
<?php
|
||
// Определяем единицу измерения для отображения
|
||
$is_orgsteklo = isset( $cart_item['orgsteklo_calculator'] );
|
||
$unit_label = $is_orgsteklo ? 'лист' : 'шт';
|
||
?>
|
||
<?php if ( $is_orgsteklo ) : ?>
|
||
<?php
|
||
// Для оргстекла: Итоговая цена за 1 кг
|
||
$price_per_kg = isset( $cart_item['orgsteklo_calculator']['price_per_kg'] )
|
||
? $cart_item['orgsteklo_calculator']['price_per_kg']
|
||
: ( $weight > 0 ? $price / $weight : 0 );
|
||
?>
|
||
<div class="cart-product__chars-row">
|
||
<p>Итоговая цена за 1 кг:</p>
|
||
<p class="cart-product__chars-price"><?php echo wc_price( $price_per_kg ); ?></p>
|
||
</div>
|
||
<div class="cart-product__chars-row">
|
||
<p>Вес:</p>
|
||
<p><?php echo number_format($weight, 3, '.', ' '); ?> кг</p>
|
||
</div>
|
||
<?php else : ?>
|
||
<div class="cart-product__chars-row">
|
||
<p>Вес 1 <?php echo $unit_label; ?>:</p>
|
||
<p><?php echo number_format($weight, 3, '.', ' '); ?> кг</p>
|
||
</div>
|
||
<div class="cart-product__chars-row">
|
||
<p>Итоговая цена за 1 <?php echo $unit_label; ?>:</p>
|
||
<p class="cart-product__chars-price"><?php echo wc_price($price); ?></p>
|
||
<?php if ($regular_price > $price): ?>
|
||
<p class="cart-product__chars-oldprice"><?php echo wc_price($regular_price); ?></p>
|
||
<?php endif; ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
</div>
|
||
<div class="cart-product__quantity">
|
||
<p>Количество</p>
|
||
<?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 );
|
||
?>
|
||
</div>
|
||
<a href="#" class="cart-product__delete" data-cart_item_key="<?php echo esc_attr($cart_item_key); ?>" data-product_name="<?php echo esc_attr($product_name); ?>" data-remove_url="<?php echo esc_url( wc_get_cart_remove_url( $cart_item_key ) ); ?>" aria-label="<?php echo esc_attr( sprintf( __( 'Remove %s from cart', 'woocommerce' ), wp_strip_all_tags( $product_name ) ) ); ?>">Удалить<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M6.46875 13.5356L13.5398 6.46458" stroke="#C4C4C4" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M13.5398 13.5354L6.46875 6.46436" stroke="#C4C4C4" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg></a>
|
||
</div>
|
||
<div class="cart-product__info">
|
||
<?php
|
||
$product_id_for_tags = $_product->is_type('variation') ? $_product->get_parent_id() : $_product->get_id();
|
||
|
||
// Показываем статусные теги (не скидки)
|
||
if ( function_exists('get_sorted_product_tags') && function_exists('is_discount_tag') ) {
|
||
$sorted_tags = get_sorted_product_tags( $product_id_for_tags );
|
||
foreach ( $sorted_tags as $tag ) {
|
||
if ( ! is_discount_tag( $tag->name ) ) {
|
||
echo '<p class="cart-product__popular">' . esc_html( $tag->name ) . '</p>';
|
||
}
|
||
}
|
||
}
|
||
|
||
// Получаем процент скидки из тегов товара
|
||
$discount_percent = 0;
|
||
if ( function_exists('get_sorted_product_tags') && function_exists('is_discount_tag') && function_exists('get_discount_from_tag_name') ) {
|
||
$tags = get_sorted_product_tags( $product_id_for_tags );
|
||
foreach ( $tags as $tag ) {
|
||
if ( is_discount_tag( $tag->name ) ) {
|
||
$discount_percent = get_discount_from_tag_name( $tag->name );
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
if ( $discount_percent > 0 ) :
|
||
?>
|
||
<p class="cart-product__discount">-<?php echo $discount_percent; ?>%</p>
|
||
<?php endif; ?>
|
||
<div class="cart-product__info-col">
|
||
<p class="cart-product__info-label">Итоговая стоимость:</p>
|
||
<div class="cart-product__info-block">
|
||
<div class="cart-product__price-row">
|
||
<p class="cart-product__price"><?php echo wc_price($total_price); ?></p>
|
||
<?php if ($total_regular_price > $total_price): ?>
|
||
<p class="cart-product__oldprice"><?php echo wc_price($total_regular_price); ?></p>
|
||
<?php endif; ?>
|
||
</div>
|
||
</div>
|
||
<div class="cart-product__info-block">
|
||
<p>Итоговый вес:</p>
|
||
<p><?php echo number_format($total_weight, 3, '.', ' '); ?> кг</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<?php
|
||
}
|
||
}
|
||
?>
|
||
<?php do_action( 'woocommerce_cart_contents' ); ?>
|
||
<?php do_action( 'woocommerce_after_cart_contents' ); ?>
|
||
</div>
|
||
<?php do_action( 'woocommerce_after_cart_table' ); ?>
|
||
</form>
|
||
</div>
|
||
<div class="cart-right">
|
||
<div class="cart-total">
|
||
<h3>Ваш заказ</h3>
|
||
<div class="cart-total__col">
|
||
<div class="cart-total__info">
|
||
<?php
|
||
$count = WC()->cart->get_cart_contents_count();
|
||
function plural_form($number, $forms) {
|
||
$n = abs($number) % 100;
|
||
$n1 = $n % 10;
|
||
if ($n > 10 && $n < 20) return $forms[2];
|
||
if ($n1 > 1 && $n1 < 5) return $forms[1];
|
||
if ($n1 == 1) return $forms[0];
|
||
return $forms[2];
|
||
}
|
||
$word = plural_form($count, ['товар', 'товара', 'товаров']);
|
||
?>
|
||
<div class="cart-total__info-row">
|
||
<p>Количество товаров:</p>
|
||
<p><?php echo $count . ' ' . $word; ?></p>
|
||
</div>
|
||
<?php
|
||
$cart = WC()->cart;
|
||
$total_weight = 0;
|
||
foreach ( $cart->get_cart() as $item ) {
|
||
$product = $item['data'];
|
||
$qty = $item['quantity'];
|
||
$weight = (float) $product->get_weight();
|
||
$total_weight += $weight * $qty;
|
||
}
|
||
?>
|
||
<div class="cart-total__info-row">
|
||
<p>Вес заказа:</p>
|
||
<p><?php echo number_format($total_weight, 3, '.', ' '); ?> кг</p>
|
||
</div>
|
||
<?php
|
||
$cart = WC()->cart;
|
||
$items = $cart->get_cart();
|
||
$regular_total = 0;
|
||
$sale_total = 0;
|
||
foreach ( $items as $item ) {
|
||
$product = $item['data'];
|
||
$quantity = $item['quantity'];
|
||
$regular_price = $product->get_regular_price();
|
||
$sale_price = $product->get_sale_price();
|
||
if ( $sale_price === '' ) {
|
||
$sale_price = $regular_price;
|
||
}
|
||
$regular_total += $regular_price * $quantity;
|
||
$sale_total += $sale_price * $quantity;
|
||
}
|
||
|
||
// Округляем суммы
|
||
$regular_total = round($regular_total);
|
||
$sale_total = round($sale_total);
|
||
|
||
// Скидка на товары
|
||
$product_discount = $regular_total - $sale_total;
|
||
|
||
// Скидка от суммы заказа (порог проверяется по сумме СО скидками на товары)
|
||
$cart_discount = function_exists('orgsteklo_calculate_cart_discount')
|
||
? orgsteklo_calculate_cart_discount( $sale_total )
|
||
: array( 'percent' => 0, 'amount' => 0 );
|
||
$discount_from_total = $cart_discount['amount'];
|
||
|
||
// Итоговая сумма
|
||
$final_total = $sale_total - $discount_from_total;
|
||
?>
|
||
<div class="cart-total__info-row">
|
||
<p>Стоимость товара без скидки:</p>
|
||
<p><?php echo wc_price($regular_total); ?></p>
|
||
</div>
|
||
<div class="cart-total__info-row">
|
||
<p>Скидка на товар:</p>
|
||
<p><?php echo wc_price($product_discount); ?></p>
|
||
</div>
|
||
<?php if ( $discount_from_total > 0 ) : ?>
|
||
<div class="cart-total__info-row">
|
||
<p>Скидка от суммы заказа (<?php echo $cart_discount['percent']; ?>%):</p>
|
||
<p><?php echo wc_price($discount_from_total); ?></p>
|
||
</div>
|
||
<?php endif; ?>
|
||
</div>
|
||
<div class="cart-total__bottom">
|
||
<?php
|
||
// Используем уже рассчитанные значения выше
|
||
?>
|
||
<div class="cart-total__price-col">
|
||
<p>Стоимость заказа:</p>
|
||
<div class="cart-total__price-row">
|
||
<p class="cart-total__price"><?php echo number_format($final_total, 0, ',', ' '); ?> <span>₽</span></p>
|
||
<?php if ( $regular_total > $final_total ) : ?>
|
||
<p class="cart-total__oldprice"><?php echo number_format($regular_total, 0, ',', ' '); ?> <span>₽</span></p>
|
||
<?php endif; ?>
|
||
</div>
|
||
</div>
|
||
<a href="/checkout" class="cart-submit">
|
||
Перейти к оформлению заказа
|
||
<svg width="19" height="18" viewBox="0 0 19 18" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M11.3242 4.44727L15.8767 8.99977L11.3242 13.5523" stroke="white" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/><path d="M3.125 9H15.7475" stroke="white" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/></svg>
|
||
</a>
|
||
<p>Доступные способы доставки и оплаты можно выбрать при оформлении заказа.</p>
|
||
<p><a href="/login" style="color: var(--Blue);">Войти</a>, чтобы отслеживать статус заказа.</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<?php do_action( 'woocommerce_after_cart' ); ?>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<script>
|
||
document.addEventListener("DOMContentLoaded", function () {
|
||
const cartForm = document.querySelector(".woocommerce-cart-form");
|
||
const quantityInputs = document.querySelectorAll(".cart-product__quantity-row input");
|
||
if (cartForm && quantityInputs.length) {
|
||
quantityInputs.forEach((input) => {
|
||
input.addEventListener("change", function () {
|
||
document.querySelector("input[name='update_checkout_cart']").value = "1";
|
||
cartForm.submit();
|
||
});
|
||
});
|
||
document.querySelectorAll(".cart-product__quantity-plus, .cart-product__quantity-minus").forEach((button) => {
|
||
button.addEventListener("click", function () {
|
||
setTimeout(() => {
|
||
document.querySelector("input[name='update_checkout_cart']").value = "1";
|
||
cartForm.submit();
|
||
}, 300);
|
||
});
|
||
});
|
||
}
|
||
});
|
||
|
||
document.addEventListener('DOMContentLoaded', function() {
|
||
const popup = document.querySelector('.popup-cart-product');
|
||
const popupName = popup.querySelector('.popup-cart__name h4');
|
||
const popupDeleteBtn = popup.querySelector('.popup-cart__delete');
|
||
const popupCancelBtns = popup.querySelectorAll('.popup-cart__close');
|
||
|
||
let removeUrl = null; // сюда будем сохранять ссылку удаления
|
||
|
||
// Открываем popup по клику на "Удалить"
|
||
document.querySelectorAll('.cart-product__delete').forEach(button => {
|
||
button.addEventListener('click', function(e) {
|
||
e.preventDefault();
|
||
const productName = this.getAttribute('data-product_name');
|
||
removeUrl = this.getAttribute('data-remove_url');
|
||
|
||
popupName.textContent = productName;
|
||
popup.style.display = 'flex';
|
||
});
|
||
});
|
||
|
||
// Закрываем popup по кнопкам "Отмена" и крестик
|
||
popupCancelBtns.forEach(btn => {
|
||
btn.addEventListener('click', () => {
|
||
popup.style.display = 'none';
|
||
removeUrl = null;
|
||
});
|
||
});
|
||
|
||
// При подтверждении удаляем товар — просто переходим по ссылке удаления
|
||
popupDeleteBtn.addEventListener('click', () => {
|
||
if (removeUrl) {
|
||
window.location.href = removeUrl;
|
||
}
|
||
});
|
||
});
|
||
|
||
document.addEventListener('DOMContentLoaded', function() {
|
||
const checkboxAll = document.getElementById('cart-checkbox__all');
|
||
const productCheckboxes = document.querySelectorAll('.cart-product__checkbox input[type="checkbox"]');
|
||
const btnDeleteSelected = document.querySelector('.cart-delete-all');
|
||
const popup = document.querySelector('.popup-cart');
|
||
const popupCancelBtns = popup.querySelectorAll('.popup-cart__close');
|
||
const popupDeleteBtn = popup.querySelector('.popup-cart__delete');
|
||
const form = document.querySelector('.woocommerce-cart-form');
|
||
|
||
// Выбор/снятие выбора всех
|
||
checkboxAll.addEventListener('change', function() {
|
||
productCheckboxes.forEach(chk => {
|
||
chk.checked = checkboxAll.checked;
|
||
});
|
||
});
|
||
|
||
// Обновляем чекбокс "выбрать все"
|
||
productCheckboxes.forEach(chk => {
|
||
chk.addEventListener('change', function() {
|
||
const allChecked = Array.from(productCheckboxes).every(chk => chk.checked);
|
||
checkboxAll.checked = allChecked;
|
||
});
|
||
});
|
||
|
||
// Открываем попап подтверждения удаления
|
||
btnDeleteSelected.addEventListener('click', function(e) {
|
||
e.preventDefault();
|
||
const anyChecked = Array.from(productCheckboxes).some(chk => chk.checked);
|
||
if (!anyChecked) {
|
||
alert('Выберите хотя бы один товар для удаления.');
|
||
return;
|
||
}
|
||
popup.style.display = 'flex';
|
||
});
|
||
|
||
// Закрываем попап
|
||
popupCancelBtns.forEach(btn => {
|
||
btn.addEventListener('click', () => {
|
||
popup.style.display = 'none';
|
||
});
|
||
});
|
||
|
||
// При подтверждении удаления
|
||
popupDeleteBtn.addEventListener('click', () => {
|
||
// Собираем выбранные ключи корзины ПЕРЕД удалением
|
||
const selectedKeys = Array.from(productCheckboxes)
|
||
.filter(chk => chk.checked)
|
||
.map(chk => chk.value);
|
||
|
||
// Удаляем старые hidden поля (только type=hidden, не чекбоксы)
|
||
form.querySelectorAll('input[type="hidden"][name="cart_product_keys[]"]').forEach(el => el.remove());
|
||
|
||
// Для каждого выбранного создаем hidden input для отправки на сервер
|
||
selectedKeys.forEach(key => {
|
||
const input = document.createElement('input');
|
||
input.type = 'hidden';
|
||
input.name = 'cart_product_keys[]';
|
||
input.value = key;
|
||
form.appendChild(input);
|
||
});
|
||
|
||
// Добавляем поле, сигнализирующее об удалении
|
||
let inputDelete = form.querySelector('input[name="delete_selected"]');
|
||
if (!inputDelete) {
|
||
inputDelete = document.createElement('input');
|
||
inputDelete.type = 'hidden';
|
||
inputDelete.name = 'delete_selected';
|
||
inputDelete.value = '1';
|
||
form.appendChild(inputDelete);
|
||
}
|
||
|
||
form.submit();
|
||
});
|
||
});
|
||
|
||
|
||
|
||
</script>
|
||
<div class="popup popup-cart">
|
||
<div class="popup-fon popup-cart__fon"></div>
|
||
<div class="popup-main">
|
||
<button class="popup-close popup-cart__close"><svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#clip0_1269_41481)"><path d="M23.7068 0.293275C23.5193 0.105804 23.2649 0.000488281 22.9998 0.000488281C22.7346 0.000488281 22.4803 0.105804 22.2928 0.293275L11.9998 10.5863L1.70679 0.293275C1.51926 0.105804 1.26495 0.000488281 0.999786 0.000488281C0.734622 0.000488281 0.480314 0.105804 0.292786 0.293275C0.105315 0.480802 0 0.735111 0 1.00027C0 1.26544 0.105315 1.51975 0.292786 1.70727L10.5858 12.0003L0.292786 22.2933C0.105315 22.4808 0 22.7351 0 23.0003C0 23.2654 0.105315 23.5197 0.292786 23.7073C0.480314 23.8947 0.734622 24.0001 0.999786 24.0001C1.26495 24.0001 1.51926 23.8947 1.70679 23.7073L11.9998 13.4143L22.2928 23.7073C22.4803 23.8947 22.7346 24.0001 22.9998 24.0001C23.2649 24.0001 23.5193 23.8947 23.7068 23.7073C23.8943 23.5197 23.9996 23.2654 23.9996 23.0003C23.9996 22.7351 23.8943 22.4808 23.7068 22.2933L13.4138 12.0003L23.7068 1.70727C23.8943 1.51975 23.9996 1.26544 23.9996 1.00027C23.9996 0.735111 23.8943 0.480802 23.7068 0.293275Z" fill="#808080"/></g><defs><clipPath id="clip0_1269_41481"><rect width="24" height="24" fill="white"/></clipPath></defs></svg></button>
|
||
<div class="popup-cart__col">
|
||
<div class="popup-cart__name">
|
||
<h4>Удалить выбранные товары</h4>
|
||
<p>Вы точно хотите удалить выбранные товары из корзины? <br> Отменить данное действие будет невозможно.</p>
|
||
</div>
|
||
<div class="popup-cart__buttons">
|
||
<button class="popup-cart__cancel popup-cart__close">Отмена</button>
|
||
<button class="popup-cart__delete">Да, удалить</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="popup popup-cart-product">
|
||
<div class="popup-fon popup-cart-product__fon"></div>
|
||
<div class="popup-main">
|
||
<button class="popup-close popup-cart-product__close"><svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#clip0_1269_41481)"><path d="M23.7068 0.293275C23.5193 0.105804 23.2649 0.000488281 22.9998 0.000488281C22.7346 0.000488281 22.4803 0.105804 22.2928 0.293275L11.9998 10.5863L1.70679 0.293275C1.51926 0.105804 1.26495 0.000488281 0.999786 0.000488281C0.734622 0.000488281 0.480314 0.105804 0.292786 0.293275C0.105315 0.480802 0 0.735111 0 1.00027C0 1.26544 0.105315 1.51975 0.292786 1.70727L10.5858 12.0003L0.292786 22.2933C0.105315 22.4808 0 22.7351 0 23.0003C0 23.2654 0.105315 23.5197 0.292786 23.7073C0.480314 23.8947 0.734622 24.0001 0.999786 24.0001C1.26495 24.0001 1.51926 23.8947 1.70679 23.7073L11.9998 13.4143L22.2928 23.7073C22.4803 23.8947 22.7346 24.0001 22.9998 24.0001C23.2649 24.0001 23.5193 23.8947 23.7068 23.7073C23.8943 23.5197 23.9996 23.2654 23.9996 23.0003C23.9996 22.7351 23.8943 22.4808 23.7068 22.2933L13.4138 12.0003L23.7068 1.70727C23.8943 1.51975 23.9996 1.26544 23.9996 1.00027C23.9996 0.735111 23.8943 0.480802 23.7068 0.293275Z" fill="#808080"/></g><defs><clipPath id="clip0_1269_41481"><rect width="24" height="24" fill="white"/></clipPath></defs></svg></button>
|
||
<div class="popup-cart__col">
|
||
<div class="popup-cart__name">
|
||
<h4>Акрил прозрачный 1,5мм (оргстекло) экструдированный, Quinn Plastics</h4>
|
||
<p>Вы точно хотите удалить выбранный товар из корзины? <br> Отменить данное действие будет невозможно.</p>
|
||
</div>
|
||
<div class="popup-cart__buttons">
|
||
<button class="popup-cart__cancel popup-cart__close">Отмена</button>
|
||
<button class="popup-cart__delete">Да, удалить</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|