Plugin Directory

Changeset 3305056


Ignore:
Timestamp:
06/02/2025 01:19:51 PM (10 months ago)
Author:
wootro
Message:

Fix: Prevent null warnings when accessing chosen shipping method in checkout flow

Location:
woot-ro/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • woot-ro/trunk/README.txt

    r3305044 r3305056  
    33Tags: shipping, couriers, delivery, romania, ecommerce
    44Requires at least: 4.0
    5 Tested up to: 6.6.2
    6 Stable tag: 2.0.6
     5Tested up to: 6.8.1
     6Stable tag: 2.0.7
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    7777* Fix warning when checking for existing shipping method
    7878
     79= 2.0.7 =
     80* Fix: Prevent null warnings when accessing chosen shipping method in checkout flow
     81
    7982== Upgrade Notice ==
    8083
     
    103106= 2.0.6 =
    104107* Fix warning when checking for existing shipping method
     108
     109= 2.0.7 =
     110* Fix: Prevent null warnings when accessing chosen shipping method in checkout flow
  • woot-ro/trunk/includes/class-woot-woocommerce.php

    r3153925 r3305056  
    4141        if ($enabled && (is_cart() || is_checkout())) {
    4242            $shipping_methods = WC()->session->get('chosen_shipping_methods');
    43             $shipping_method = explode(':', $shipping_methods[0]);
    44 
    45             if (!empty($shipping_method[0])) {
    46                 $settings = get_option('woocommerce_' . $shipping_method[0] . '_' . $shipping_method[1] . '_settings');
    47 
    48                 if (!empty($settings['couriers'])) {
    49                     $couriers = $settings['couriers'];
    50 
    51                     $this->couriers = array_values(array_filter($this->couriers, function ($row) use ($couriers) {
    52                         return in_array($row['uid'], $couriers);
    53                     }));
     43
     44            if (is_array($shipping_methods) && !empty($shipping_methods[0])) {
     45                $shipping_method_parts = explode(':', $shipping_methods[0]);
     46
     47                if (!empty($shipping_method_parts[0]) && !empty($shipping_method_parts[1])) {
     48                    $settings = get_option('woocommerce_' . $shipping_method_parts[0] . '_' . $shipping_method_parts[1] . '_settings');
     49
     50                    if (!empty($settings['couriers'])) {
     51                        $couriers = $settings['couriers'];
     52
     53                        $this->couriers = array_values(array_filter($this->couriers, function ($row) use ($couriers) {
     54                            return in_array($row['uid'], $couriers);
     55                        }));
     56                    }
    5457                }
    5558            }
    5659        }
     60
    5761
    5862        return $this->couriers;
     
    277281        if (is_checkout()) {
    278282            $shipping_methods = WC()->session->get('chosen_shipping_methods');
    279             $shipping_method = explode(':', $shipping_methods[0]);
    280 
    281             if (!empty($shipping_method)) {
    282                 if ($shipping_method[0] === 'woot_locations') {
     283
     284            if (is_array($shipping_methods) && !empty($shipping_methods[0])) {
     285                $shipping_method = explode(':', $shipping_methods[0]);
     286
     287                if (!empty($shipping_method) && isset($shipping_method[0]) && $shipping_method[0] === 'woot_locations') {
    283288                    echo '<tr class="woocommerce-wt-locations">';
    284289                    echo '<th></th>';
     
    308313    {
    309314        $shipping_methods = WC()->session->get('chosen_shipping_methods');
    310         $shipping_method = explode(':', $shipping_methods[0]);
    311 
    312         if ($shipping_method[0] === 'woot_locations' && empty($_POST['location_id'])) {
    313             wc_add_notice(__('Please select a location!'), 'error');
     315
     316        if (is_array($shipping_methods) && !empty($shipping_methods[0])) {
     317            $shipping_method = explode(':', $shipping_methods[0]);
     318
     319            if (isset($shipping_method[0]) && $shipping_method[0] === 'woot_locations' && empty($_POST['location_id'])) {
     320                wc_add_notice(__('Please select a location!'), 'error');
     321            }
    314322        }
    315323    }
     
    363371    {
    364372        if (is_checkout()) {
    365             $shipping = WC()->session->get('chosen_shipping_methods');
    366             $shipping = explode(':', $shipping[0]);
    367 
    368             if (!empty($shipping[0])) {
    369                 $shipping_settings = get_option('woocommerce_' . $shipping[0] . '_' . $shipping[1] . '_settings');
    370                 $payment_id = WC()->session->get('chosen_payment_method');
    371 
    372                 if (!empty($shipping_settings[$payment_id . '_' . 'price'])) {
    373                     $gateways = WC_Payment_Gateways::instance();
    374                     $payment = $gateways->payment_gateways()[$payment_id];
    375 
    376                     $cart->add_fee($payment->title, $shipping_settings[$payment_id . '_' . 'price'], !empty($cart->get_shipping_tax()));
     373            $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
     374
     375            if (is_array($chosen_shipping_methods) && !empty($chosen_shipping_methods[0])) {
     376                $shipping_parts = explode(':', $chosen_shipping_methods[0]);
     377
     378                if (!empty($shipping_parts[0]) && !empty($shipping_parts[1])) {
     379                    $shipping_settings = get_option('woocommerce_' . $shipping_parts[0] . '_' . $shipping_parts[1] . '_settings');
     380                    $payment_id = WC()->session->get('chosen_payment_method');
     381
     382                    if (!empty($shipping_settings[$payment_id . '_price'])) {
     383                        $gateways = WC_Payment_Gateways::instance();
     384                        $payment = $gateways->payment_gateways()[$payment_id] ?? null;
     385
     386                        if ($payment) {
     387                            $cart->add_fee($payment->title, $shipping_settings[$payment_id . '_price'], !empty($cart->get_shipping_tax()));
     388                        }
     389                    }
    377390                }
    378391            }
  • woot-ro/trunk/public/class-woot-public.php

    r3305044 r3305056  
    130130
    131131                $shipping_methods = WC()->session->get('chosen_shipping_methods');
    132                 $shipping_method = explode(':', $shipping_methods[0]);
    133132
    134                 if (isset($shipping_method[0]) && isset($shipping_method[1])) {
    135                     $settings = get_option('woocommerce_' . $shipping_method[0] . '_' . $shipping_method[1] . '_settings');
     133                if (is_array($shipping_methods) && !empty($shipping_methods[0])) {
     134                    $shipping_method_parts = explode(':', $shipping_methods[0]);
    136135
    137                     if (!empty($settings['couriers'])) {
    138                         $couriers = $settings['couriers'];
     136                    if (isset($shipping_method_parts[0], $shipping_method_parts[1])) {
     137                        $settings = get_option('woocommerce_' . $shipping_method_parts[0] . '_' . $shipping_method_parts[1] . '_settings');
     138
     139                        if (!empty($settings['couriers'])) {
     140                            $couriers = $settings['couriers'];
     141                        }
    139142                    }
    140143                }
  • woot-ro/trunk/woot.php

    r3305044 r3305056  
    1717 * Plugin URI:        https://woot.ro
    1818 * Description:       Integrates all popular couriers in Romania, providing a one-stop solution for all your delivery needs
    19  * Version:           2.0.6
     19 * Version:           2.0.7
    2020 * Author:            Woot.ro
    2121 * Author URI:        https://woot.ro
     
    3636 * Rename this for your plugin and update it as you release new versions.
    3737 */
    38 define('WOOT_VERSION', '2.0.6');
     38define('WOOT_VERSION', '2.0.7');
    3939
    4040/**
Note: See TracChangeset for help on using the changeset viewer.