|
|
|
@ -1,25 +1,47 @@ |
|
|
|
|
<?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 |
|
|
|
|
*/ |
|
|
|
|
* TO_DO : вынести всю логику из данного файла |
|
|
|
|
* в отдельный компонент delivery_methods в /shop |
|
|
|
|
* разметку вынести в твиг файл в /templates/shop/delivery_methods.twig |
|
|
|
|
**/ |
|
|
|
|
|
|
|
|
|
defined( 'ABSPATH' ) || exit; |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
Start : функция для проверки и перевода количества времени доставки |
|
|
|
|
предоставляемого плагином CDEK в фомате {X} day |
|
|
|
|
Вход строка формата {X} day |
|
|
|
|
Выход - строка формата {X} день/дня/дней для русского языка |
|
|
|
|
*/ |
|
|
|
|
function translate_days($text_in_parentheses) { |
|
|
|
|
// Проверим язык сайта |
|
|
|
|
if (function_exists('pll_current_language') && pll_current_language() === 'ru') { |
|
|
|
|
// Разбиваем строку на число и слово |
|
|
|
|
if (preg_match('/^(\d+)\s+day$/', $text_in_parentheses, $matches)) { |
|
|
|
|
$number = (int)$matches[1]; |
|
|
|
|
// Склонение слова "день" |
|
|
|
|
$remainder10 = $number % 10; |
|
|
|
|
$remainder100 = $number % 100; |
|
|
|
|
|
|
|
|
|
if ($remainder10 == 1 && $remainder100 != 11) { |
|
|
|
|
$day_word = 'день'; |
|
|
|
|
} elseif (in_array($remainder10, [2, 3, 4]) && !in_array($remainder100, [12, 13, 14])) { |
|
|
|
|
$day_word = 'дня'; |
|
|
|
|
} else { |
|
|
|
|
$day_word = 'дней'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $number . ' ' . $day_word; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Если не русский язык или формат не соответствует — вернуть как есть |
|
|
|
|
return $text_in_parentheses; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
End : функция для проверки и перевода количества времени доставки |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
$formatted_destination = isset( $formatted_destination ) ? $formatted_destination : WC()->countries->get_formatted_address( $package['destination'], ', ' ); |
|
|
|
|
$has_calculated_shipping = ! empty( $has_calculated_shipping ); |
|
|
|
@ -47,6 +69,8 @@ $calculator_text = ''; |
|
|
|
|
$text_in_parentheses = ''; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$text_in_parentheses = translate_days($text_in_parentheses); |
|
|
|
|
|
|
|
|
|
if ($text_before_comma == 'CDEK: Посылка склад-дверь' || $text_before_comma == 'CDEK: Package warehouse to door'){ |
|
|
|
|
$title = pll__('Курьером'); |
|
|
|
|
} |
|
|
|
|