From 3077d7ee75861d1fd7a7832d3a86556905f6bccd Mon Sep 17 00:00:00 2001 From: maksim Date: Tue, 12 Aug 2025 15:59:52 +0300 Subject: [PATCH] =?UTF-8?q?Task=207715=20|=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=BB=20=D0=B4=D0=B8=D0=BD=D0=B0=D0=BC=D0=B8=D1=87?= =?UTF-8?q?=D0=B5=D1=81=D0=BA=D0=BE=D0=B5=20=D1=80=D0=B0=D0=B7=D0=B1=D0=B8?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=86=D0=B5=D0=BD=D1=8B=20=D0=B4?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=86=D0=B5=D0=BD=D0=B0=20+=20=D0=9D=D0=94=D0=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wp-content/themes/cosmopet/functions.php | 3 +- .../modules/shop/module-controller.php | 43 +++++++++++++++++++ .../woocommerce/checkout/review-order.php | 2 + 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/wp-content/themes/cosmopet/functions.php b/wp-content/themes/cosmopet/functions.php index 11e2321..486614a 100644 --- a/wp-content/themes/cosmopet/functions.php +++ b/wp-content/themes/cosmopet/functions.php @@ -24,6 +24,7 @@ require_once __DIR__ . '/temp-functions/login-logic.php'; // include_module('author'); // include_module('layout'); + include_once('modules/shop/CosmopetProduct.php'); add_filter('timber/post/classmap', function ($classmap) { @@ -36,4 +37,4 @@ function allow_svg_upload($mimes) { $mimes['svg'] = 'image/svg+xml'; return $mimes; } -add_filter('upload_mimes', 'allow_svg_upload'); \ No newline at end of file +add_filter('upload_mimes', 'allow_svg_upload'); diff --git a/wp-content/themes/cosmopet/modules/shop/module-controller.php b/wp-content/themes/cosmopet/modules/shop/module-controller.php index 744456a..3e1bf03 100644 --- a/wp-content/themes/cosmopet/modules/shop/module-controller.php +++ b/wp-content/themes/cosmopet/modules/shop/module-controller.php @@ -403,3 +403,46 @@ function map_attr_slugs_to_class($slug) { return $slug_map[$slug] ?? $slug; // Fallback to original slug if not found } + + +// Изменение цены доставки на разбиение НДС + основная стоимость +add_filter( 'woocommerce_package_rates', function( $rates, $package ) { + + foreach ( $rates as $rate_id => $rate ) { + + // Цена от плагина (итоговая с налогом) + $final_shipping_with_tax = $rate->cost; + + // Получаем налоговую ставку для этого метода + $tax_rates = WC_Tax::get_rates( $rate->tax_class ); + if ( empty( $tax_rates ) ) { + continue; // если нет налога + } + + // Берём первую найденную ставку + $tax_rate_key = key( $tax_rates ); + $tax_rate_data = reset( $tax_rates ); + $tax_percent = floatval( $tax_rate_data['rate'] ); + + // Считаем коэффициент + $coef = 1 / ( 1 + $tax_percent / 100 ); + + // Цена без налога + $base_shipping = round( $final_shipping_with_tax * $coef, wc_get_price_decimals() ); + + // Налог как разница + $tax_amount = round( $final_shipping_with_tax - $base_shipping, wc_get_price_decimals() ); + + // Устанавливаем + $rate->cost = $base_shipping; + + // Заполняем налоги корректно для WooCommerce + $taxes_array = array_fill_keys( array_keys( WC_Tax::get_rates( $rate->tax_class ) ), 0 ); + $taxes_array[$tax_rate_key] = $tax_amount; + + $rate->taxes = $taxes_array; + } + + return $rates; + +}, 100, 2 ); diff --git a/wp-content/themes/cosmopet/woocommerce/checkout/review-order.php b/wp-content/themes/cosmopet/woocommerce/checkout/review-order.php index c0b0378..4c5e1c3 100644 --- a/wp-content/themes/cosmopet/woocommerce/checkout/review-order.php +++ b/wp-content/themes/cosmopet/woocommerce/checkout/review-order.php @@ -65,6 +65,8 @@ defined( 'ABSPATH' ) || exit; else: ?> cart->get_shipping_total() + WC()->cart->get_shipping_tax() ?> + +