X   Сообщение сайта
(Сообщение закроется через 3 секунды)



 

Здравствуйте, гость (

| Вход | Регистрация )

Открыть тему
Тема закрыта
> WOO. Изменить отображаемую цену доставки
Palundra
Palundra
Topic Starter сообщение 19.5.2023, 15:12; Ответить: Palundra
Сообщение #1


Всем привет!
Подскажите, возможно ли организовать такую правку в плагине от DHL?

Цена доставки отображается не в той валюте. DHL через свой API отдает цену по моему договору в рублях. Валюта на моем сайта $.
К примеру: при оформлении доставки отображается сумма 3500 (это сумма которую дает DHL по моему тарифу), но раз сайт у меня с валютой $, получается стоимость доставки $3500 )))
DHL ничем помочь не может. Цену ан доставку отдают только в валюте по договора.

Возможно как то через этот плагин менять цену с учетом прописанного где то курса в $?

Если кто может такое организовать, пишите цену в личку.

Сам плагин в одном файле
Прикрепленный файл  woocommerce_dhlexpress_services.php ( 9,42 килобайт ) Кол-во скачиваний: 26


--------------------
0
Вернуться в начало страницы
 
Ответить с цитированием данного сообщения
OS_ZP_UA
OS_ZP_UA
сообщение 19.5.2023, 17:15; Ответить: OS_ZP_UA
Сообщение #2


Palundra, файл битый, но да, бери и дели переменную отвечающую за цену на курс...
Вернуться в начало страницы
 
Ответить с цитированием данного сообщения
Palundra
Palundra
Topic Starter сообщение 19.5.2023, 17:49; Ответить: Palundra
Сообщение #3


OS_ZP_UA, можете показать где? Я не силен в коде )


Код
<?php
/**
* Plugin Name: DHL Express Commerce
* Plugin URI: https://www.dhlexpresscommerce.com/
* Description: Provides DHL Express shipping rates at checkout.
* Author: DHL Express
* Author URI: https://www.dhlexpresscommerce.com/
* Version: 3.0.0
*
* Copyright (c) 2019 StarShipIT
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

if ( ! defined( 'ABSPATH' ) ) {
  exit;
}

function dhlexpress_is_woocommerce_active() {
    
    $wc_active = (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))));
    
    if ($wc_active) {
        return $wc_active;
    } else {
        if (is_multisite()) {
            // WordPress multisite detected
            $wc_active = (array_key_exists('woocommerce/woocommerce.php', apply_filters('active_plugins', get_site_option('active_sitewide_plugins'))));
        }
    }
    
    return $wc_active;
}

// Ensure WooCommerce is active
if (dhlexpress_is_woocommerce_active()) {

  function dhlexpress_services_init() {
  
    if (! class_exists('WC_DHLExpress_Rates')) {
        
      class WC_DHLExpress_Rates extends WC_Shipping_Method {

        public function __construct() {
          $this -> id = 'dhlexpress';
          $this -> method_title = __('DHL Express Shipping Rates');
          $this -> method_description = __('Display live shipping rates at checkout via DHL Express API service');
          
          $this -> apikey = "";
          $this -> enabled = "yes";
          $this -> init();
        }

        function init() {
          $this -> init_form_fields();
          $this -> init_settings();
          $this -> apikey = $this -> settings['apikey'];
          $this -> enabled = $this -> settings['enabled'];
          
          add_action('woocommerce_update_options_shipping_' . $this -> id, array($this, 'process_admin_options'));
        }
        
        function init_form_fields() {
          $this -> form_fields = array(
            'apikey' => array(
            'title' => __('API Key', 'woocommerce'),
            'type' => 'text',
            'description' => __('This is available under your DHL App account (Settings > API).', 'woocommerce')
            ),
            'enabled' => array(
              'type' => 'checkbox',
              'label' => __('Enable rates at checkout', 'woocommerce'),
              'default' => 'yes'
              )
            );
        }
          
        public function calculate_shipping($package = array()) {
          if ($this -> enabled == 'no') {
            return;
          }
          
          try {
            $address = $package['destination']['address'];
            $address_2 = $package['destination']['address_2'];
            $city = $package['destination']['city'];
            $state = $package['destination']['state'];
            $postcode = $package['destination']['postcode'];
            $countrycode = $package['destination']['country'];
            
            $counter = 0;
            $itemList = '';

            try {
              $dimension_unit = get_option('woocommerce_dimension_unit');

              foreach ($package['contents'] as $package_item) {
                $product = $package_item[ 'data' ];
                $productName = str_replace('"', '\\"', $product->get_title());;
                $productPrice = $product->get_price();
                $quantity = $package_item[ 'quantity' ];
              
                if (($quantity > 0) && $product -> needs_shipping()) {
                  $weight = $product -> get_weight();
                  $height = 0;
                  $length = 0;
                  $width = 0;
                
                  if ($product -> has_dimensions()) {
                    $height = $product -> get_height();
                    $length = $product -> get_length();
                    $width = $product -> get_width();
                  }

                  $itemList .= '{
                    "name": "' . $productName . '",
                    "sku": null,
                    "quantity": ' . $quantity . ',
                    "grams": ' . $weight . ',
                    "height": ' . $height . ',
                    "width": ' . $width . ',
                    "length": ' . $length . ',
                    "price": ' . $productPrice . ',
                    "dimensions_unit": "' . $dimension_unit . '",
                    "vendor": null,
                    "requires_shipping": true,
                    "taxable": true,
                    "fulfillment_service": "manual"
                  },';
                }

                if ($counter == count($package['contents']) - 1) {
                  $itemList = rtrim($itemList, ',');
                }

                $counter++;
              }
            }
            catch (Exception $e) {
              // backwards compatibility - get the rates using the old way
              $packageValue = $package['contents_cost'];
              $packageWeight = 0;

              foreach ($package['contents'] as $package_item) {
                $product = $package_item['data'];
                $quantity = $package_item['quantity'];
              
                if (($quantity > 0) && $product -> needs_shipping()) {
                  $weight = $product -> get_weight();
                  $packageWeight += $weight * $quantity;
                }
              }

              $itemList = '{
                "name": "Total Items",
                "sku": null,
                "quantity": 1,
                "grams": ' . $packageWeight . ' ,
                "price": ' . $packageValue . ',
                "vendor": null,
                "requires_shipping": true,
                "taxable": true,
                "fulfillment_service": "manual"
              }';

              // Add DHL Express Commerce Rates Exception Logging
              $wc_logger = new WC_Logger();
              $wc_logger->add('DHL-Express-Commerce', $e);
            }
            
            $url = 'https://api.starshipit.com/api/rates/shopify?apiKey=' . $this -> apikey . '&integration_type=woocommerce&version=3.0&format=json&source=DHL';
            $post_data = '{
                            "rate": {
                              "destination":{  
                                "country": "' . $countrycode . '",
                                "postal_code": "' . $postcode . '",
                                "province": "' . $state . '",
                                "city": "' . $city . '",
                                "name": null,
                                "address1": "' . $address . '",
                                "address2": "' . $address_2 . '",
                                "address3": null,
                                "phone": null,
                                "fax": null,
                                "address_type": null,
                                "company_name": null
                              },
                              "items":[' .
                                "$itemList" .
                              ']
                            }
                          }';
                          
            $response = wp_remote_post($url, array(
              'headers' => array('Content-Type' => 'application/json; charset=utf-8'),
              'method' => 'POST',
              'body' => $post_data,
              'timeout' => 75,
              'sslverify' => 0
              )
            );
            
            $response_code = wp_remote_retrieve_response_code($response);
            $response_body = wp_remote_retrieve_body($response);
            
            $json_obj = json_decode($response_body);
            $rates_obj = $json_obj -> {'rates'};
            
            if (is_countable($rates_obj) && count($rates_obj) > 0) {
              foreach($rates_obj as $rate) {
                if (is_object($rate)) {
                  $shipping_rate = array(
                  'id' => $this -> id . '_' . $rate -> {'service_code'},
                  'label' => $rate -> {'service_name'},
                  'cost' => $rate -> {'total_price'},
                  'calc_tax' => 'per_order'
                  );
                  
                  $this -> add_rate($shipping_rate);
                }
              }
            }
          } catch (Exception $e) {
            // Add DHL Express Commerce Rates Exception Logging
            $wc_logger = new WC_Logger();
            $wc_logger->add('DHL-Express-Commerce', $e);
          }
        }
      }
    }
  }
  
  add_action('woocommerce_shipping_init', 'dhlexpress_services_init');
  
  function add_dhlexpress_rates($methods) {
    $methods['dhlexpress_rates'] = 'WC_DHLExpress_Rates';
    return $methods;
  }
  
  add_filter('woocommerce_shipping_methods', 'add_dhlexpress_rates');
}


Сообщение отредактировал Palundra - 19.5.2023, 17:51


--------------------
Вернуться в начало страницы
 
Ответить с цитированием данного сообщения
OS_ZP_UA
OS_ZP_UA
сообщение 20.5.2023, 11:00; Ответить: OS_ZP_UA
Сообщение #4


Ну
'cost' => $rate -> {'total_price'},
я так понимаю отвечает за стоимость.
Надо смотреть, что содержится в
$rate -> {'total_price'}
но будет или так
'cost' => ($rate/80) -> {'total_price'},
или так
'cost' => ($rate -> {'total_price'})/80,

Замечание модератора:
Эта тема была закрыта автоматически ввиду отсутствия активности в ней на протяжении 100+ дней.
Если Вы считаете ее актуальной и хотите оставить сообщение, то воспользуйтесь кнопкой
или обратитесь к любому из модераторов.
Вернуться в начало страницы
 
Ответить с цитированием данного сообщения
Открыть тему
Тема закрыта
2 чел. читают эту тему (гостей: 2, скрытых пользователей: 0)
Пользователей: 0


Свернуть

> Похожие темы

  Тема Ответов Автор Просмотров Последний ответ
Открытая тема (нет новых ответов) Как составить уравнение, чтобы назначить цену для товара?
2 rownong27 711 21.3.2024, 12:53
автор: Lumex
Горячая тема (нет новых ответов) Тема имеет прикрепленные файлыProfit-smm.ru - (просмотры даром)качественная раскрутка в Vk/Inst/Yt/Tg/Tiktok за наилучшую цену!
76 Romanusss 41207 21.2.2024, 13:04
автор: Romanusss
Открытая тема (нет новых ответов) Как изменить цветовую гамму основного шаблона?
1 partua 8140 13.11.2021, 1:40
автор: Silverspam
Горячая тема (нет новых ответов) Качественное семантическое ядро за разумную цену. Гарантия качества
49 AOzhgibesov 35996 24.9.2021, 2:04
автор: AOzhgibesov
Открытая тема (нет новых ответов) Качественные сайты за разумную цену
изготовление сайтов быстро, качественно, недорого (нужное подчеркнуть)
13 Aртем 9689 16.3.2020, 11:21
автор: Aртем


 



RSS Текстовая версия Сейчас: 28.3.2024, 20:55
Дизайн