Task 7715 | добавил динамическое разбиение цены доставки на цена + НДС

web_10
parent 893472a4b9
commit 3077d7ee75
  1. 3
      wp-content/themes/cosmopet/functions.php
  2. 43
      wp-content/themes/cosmopet/modules/shop/module-controller.php
  3. 2
      wp-content/themes/cosmopet/woocommerce/checkout/review-order.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');
add_filter('upload_mimes', 'allow_svg_upload');

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

@ -65,6 +65,8 @@ defined( 'ABSPATH' ) || exit;
else:
?>
<td class="order-your-calculation__value order-your-calculation__value--price"><?php echo WC()->cart->get_shipping_total() + WC()->cart->get_shipping_tax() ?> <?php echo get_woocommerce_currency_symbol(); ?></td>
<?php endif; ?>
</tr>

Loading…
Cancel
Save