Plugin Directory

Changeset 3226449


Ignore:
Timestamp:
01/21/2025 06:26:46 PM (13 months ago)
Author:
routedev
Message:

display route fee correctly in woo dashboard

Location:
routeapp/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • routeapp/trunk/public/class-routeapp-public.php

    r3208751 r3226449  
    802802                    $acceptedCanceledStatuses = get_option('routeapp_cancel_order_statuses') ? get_option('routeapp_cancel_order_statuses') : [];
    803803
    804 
    805                     foreach ($order->get_items('fee') as $fee) {
    806                         if ($fee->get_name() === $this->routeapp_get_insurance_label()) {
    807                             $insurance_selected = true;
    808                             $insurance_amount = $fee->get_amount();
    809                             if ( class_exists('Automattic\WooCommerce\Utilities\OrderUtil')
    810                               && OrderUtil::custom_orders_table_usage_is_enabled() ) {
    811                                 // HPOS usage is enabled.
    812                                 $order->update_meta_data('_routeapp_route_charge', $insurance_amount );
    813                                 $order->update_meta_data('_routeapp_route_protection', $insurance_selected);
    814                                 $order->save();
    815                             } else {
    816                                 // Traditional CPT-based orders are in use.
    817                                 update_post_meta( $order->get_id(), '_routeapp_route_charge', $insurance_amount );
    818                                 update_post_meta( $order->get_id(), '_routeapp_route_protection', $insurance_selected );
     804                    $fees = $order->get_items('fee');
     805                    if (!empty($fees)) {
     806                        foreach ($fees as $fee) {
     807                            if ($fee->get_name() === $this->routeapp_get_insurance_label()) {
     808                                $insurance_selected = true;
     809                                $insurance_amount = $fee->get_amount();
     810                                if (class_exists('Automattic\WooCommerce\Utilities\OrderUtil')
     811                                    && OrderUtil::custom_orders_table_usage_is_enabled()) {
     812                                    // HPOS usage is enabled.
     813                                    $order->update_meta_data('_routeapp_route_charge', $insurance_amount);
     814                                    $order->update_meta_data('_routeapp_route_protection', $insurance_selected);
     815                                    $order->save();
     816                                } else {
     817                                    // Traditional CPT-based orders are in use.
     818                                    update_post_meta($order->get_id(), '_routeapp_route_charge', $insurance_amount);
     819                                    update_post_meta($order->get_id(), '_routeapp_route_protection', $insurance_selected);
     820                                }
    819821                            }
    820822                        }
     823                    } else {
     824                        try {
     825                            // Check if WC()->cart exists and is accessible
     826                            if (class_exists('WC_Cart') && isset(WC()->cart) && WC()->cart instanceof WC_Cart) {
     827                                // Fallback to WC()->cart->get_fees() if no fees are present in the order
     828                                $cart_fees = WC()->cart->get_fees();
     829                                if (!empty($cart_fees)) {
     830                                    foreach ($cart_fees as $cart_fee) {
     831                                        if ($cart_fee->name === $this->routeapp_get_insurance_label()) {
     832                                            $insurance_selected = true;
     833                                            $insurance_amount = $cart_fee->amount; // Correct method for cart fee amount
     834
     835                                            if (class_exists('Automattic\WooCommerce\Utilities\OrderUtil') &&
     836                                                OrderUtil::custom_orders_table_usage_is_enabled()) {
     837                                                // HPOS usage is enabled.
     838                                                $order->update_meta_data('_routeapp_route_charge', $insurance_amount);
     839                                                $order->update_meta_data('_routeapp_route_protection', $insurance_selected);
     840                                                $order->save();
     841                                            } else {
     842                                                // Traditional CPT-based orders are in use.
     843                                                update_post_meta($order->get_id(), '_routeapp_route_charge', $insurance_amount);
     844                                                update_post_meta($order->get_id(), '_routeapp_route_protection', $insurance_selected);
     845                                            }
     846                                        }
     847                                    }
     848                                }
     849                            }
     850                        } catch (Exception $e) {
     851                            // Log the exception and ensure the application flow continues
     852                            error_log("An error occurred while processing cart fees: " . $e->getMessage());
     853                        }
     854
    821855                    }
    822                    
     856
    823857                    if ( class_exists('Automattic\WooCommerce\Utilities\OrderUtil')
    824858                        && OrderUtil::custom_orders_table_usage_is_enabled() ) {
  • routeapp/trunk/readme.txt

    r3208751 r3226449  
    66Requires at least: 4.0
    77Tested up to: 6.7.1
    8 Stable tag: 2.2.22
     8Stable tag: 2.2.23
    99Requires PHP: 5.6
    1010License: GPLv2 or later
     
    106106
    107107== Changelog ==
     108= 2.2.23 =
     109* Display correctly route fee amount in orders admin view
     110
    108111= 2.2.22 =
    109112* Fix problem for astracker shipment tracking compatibility
  • routeapp/trunk/routeapp.php

    r3208751 r3226449  
    1010 * Plugin URI:        https://route.com/for-merchants/
    1111 * Description:       Route allows shoppers to insure their orders with one-click during checkout, adding a layer of 3rd party trust while improving the customer shopping experience.
    12  * Version:           2.2.22
     12 * Version:           2.2.23
    1313 * Author:            Route
    1414 * Author URI:        https://route.com/
     
    2626 * Currently plugin version.
    2727 */
    28 define( 'ROUTEAPP_VERSION', '2.2.22' );
     28define( 'ROUTEAPP_VERSION', '2.2.23' );
    2929
    3030/**
Note: See TracChangeset for help on using the changeset viewer.