Last active
February 2, 2021 17:09
-
-
Save kalbac/d1ad858207e9f1f2fafd51e4cb20fd68 to your computer and use it in GitHub Desktop.
Диапазон сроков доставки СДЭК для плагина Woocommerce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| * Сниппет предназначен для отображения диапазона сроков доставки СДЭК в плагине для Woocommerce. | |
| * Ссылка на плагин https://woodev.ru/downloads/wc-edostavka-integration | |
| * По вопросам обращайтесь на емайл [email protected] или через контактную форму https://woodev.ru/support | |
| * Нижеприведённый код необходимо вставить в файл functions.php вашей активной темы. | |
| * Автор кода не несёт отвественности в случае возникновеня каких либо проблем при использовании данного кода. | |
| * Любые изменения которые вы вносите в код вашего сайта, вы делаете это на свой страх и риск. | |
| * Код представлен для ознакомления как есть. Вы должны понимать что с этим кодом нужно делать. Если нет то обатитесь к профессионалам. | |
| */ | |
| add_filter( 'woocommerce_edostavka_shipping_methods', 'my_custom_edostavka_shipping_methods', 10, 2 ); | |
| function my_custom_edostavka_shipping_methods( $rate, $package ) { | |
| if( class_exists( 'WC_Edostavka_Connect' ) ) { | |
| list( $method_id, $instance_id, $tariff_id ) = explode( ':', $rate['id'] ); | |
| if( $tariff_id ) { | |
| $shipping_method = WC_Shipping_Zones::get_shipping_method( $instance_id ); | |
| if( 'yes' == $shipping_method->get_option( 'show_delivery_time', 'no' ) ) { | |
| $shipping = new WC_Edostavka_Connect( $package, array( 'code' => $tariff_id, 'title' => $shipping_method->get_method_title() ) ); | |
| $response = $shipping->get_rate(); | |
| if( ! empty( $response ) ) { | |
| $min_days = $response['deliveryPeriodMin'] ? $response['deliveryPeriodMin'] : 0; | |
| $max_days = $response['deliveryPeriodMax'] ? $response['deliveryPeriodMax'] : $min_days + 1; | |
| $label = $shipping_method->get_method_title(); | |
| if( $min_days > 0 ) { | |
| $label .= sprintf( ' (от %s до %s рабочих дня/дней)', $min_days, $max_days ); | |
| } elseif( $max_days == 1 ) { | |
| $label .= ' (в течении одного рабочего дня)'; | |
| } else { | |
| $label .= sprintf( ' (в течении %s рабочих дня/дней)', $max_days ); | |
| } | |
| $rate['label'] = $label; | |
| } | |
| } | |
| } | |
| } | |
| return $rate; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment