Changeset 3443546
- Timestamp:
- 01/20/2026 08:09:40 PM (5 weeks ago)
- Location:
- routeapp/trunk
- Files:
-
- 3 edited
-
public/class-routeapp-public.php (modified) (8 diffs)
-
readme.txt (modified) (2 diffs)
-
routeapp.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
routeapp/trunk/public/class-routeapp-public.php
r3433074 r3443546 846 846 throw new Exception( "Order with ID {$order_id} could not be retrieved." ); 847 847 } 848 849 $this->updateRouteIncludedOrderStatusMetaFields( $order ); 850 848 $is_hpos = class_exists('Automattic\WooCommerce\Utilities\OrderUtil') 849 && OrderUtil::custom_orders_table_usage_is_enabled(); 850 851 $acceptedOrderStatuses = get_option('routeapp_included_order_statuses') ? get_option('routeapp_included_order_statuses') : []; 852 $acceptedCanceledStatuses = get_option('routeapp_cancel_order_statuses') ? get_option('routeapp_cancel_order_statuses') : []; 853 854 $updated = false; 855 $updated |= $this->updateRouteOrderMetaData( $order, $is_hpos, '_routeapp_included_order_statuses', $acceptedOrderStatuses ); 856 $updated |= $this->updateRouteOrderMetaData( $order, $is_hpos, '_routeapp_cancel_order_statuses', $acceptedCanceledStatuses ); 857 858 if ($updated && $is_hpos) { 859 $order->save(); 860 } 851 861 } catch ( Exception $e ) { 852 862 error_log( "An error occurred while updating Route order status meta fields for order ID {$order_id}: " . $e->getMessage() ); … … 866 876 } 867 877 $order = wc_get_order($order_id); 868 if ( class_exists('Automattic\WooCommerce\Utilities\OrderUtil') 869 && OrderUtil::custom_orders_table_usage_is_enabled() ) { 870 // HPOS usage is enabled. 878 if (!$order) { 879 return; 880 } 881 //MSS-6248, Support High-Performance Order Storage (HPOS); fall back to legacy order storage when disabled. 882 $is_hpos = class_exists('Automattic\WooCommerce\Utilities\OrderUtil') 883 && OrderUtil::custom_orders_table_usage_is_enabled(); 884 885 $updated = false; 886 887 if ($is_hpos) { 871 888 $quote = $order->get_meta('_routeapp_quote'); 872 889 } else { … … 874 891 $quote = get_post_meta($order->get_id(), '_routeapp_quote', true); 875 892 } 876 if (!$quote) { 893 894 if (!$quote) { 877 895 $cartRef = $order->get_cart_hash(); 878 896 if (!$cartRef) { … … 886 904 if (isset($cached) && is_array($cached) && isset($cached['body'])) { 887 905 888 $acceptedOrderStatuses = get_option('routeapp_included_order_statuses') ? get_option('routeapp_included_order_statuses') : [];889 $acceptedCanceledStatuses = get_option('routeapp_cancel_order_statuses') ? get_option('routeapp_cancel_order_statuses') : [];890 891 906 $fees = $order->get_items('fee'); 892 907 if (!empty($fees)) { 893 908 foreach ($fees as $fee) { 894 909 if ($fee->get_name() === $this->routeapp_get_insurance_label()) { 895 $insurance_selected = true;896 910 $insurance_amount = $fee->get_amount(); 897 if (class_exists('Automattic\WooCommerce\Utilities\OrderUtil') 898 && OrderUtil::custom_orders_table_usage_is_enabled()) { 899 // HPOS usage is enabled. 900 $order->update_meta_data('_routeapp_route_charge', $insurance_amount); 901 $order->update_meta_data('_routeapp_route_protection', $insurance_selected); 902 $order->save(); 903 } else { 904 // Traditional CPT-based orders are in use. 905 update_post_meta($order->get_id(), '_routeapp_route_charge', $insurance_amount); 906 update_post_meta($order->get_id(), '_routeapp_route_protection', $insurance_selected); 907 } 911 $updated |= $this->updateRouteOrderMetaData( $order, $is_hpos, '_routeapp_route_charge', $insurance_amount ); 912 $updated |= $this->updateRouteOrderMetaData( $order, $is_hpos, '_routeapp_route_protection', true ); 908 913 } 909 914 } … … 917 922 foreach ($cart_fees as $cart_fee) { 918 923 if ($cart_fee->name === $this->routeapp_get_insurance_label()) { 919 $insurance_selected = true;920 924 $insurance_amount = $cart_fee->amount; // Correct method for cart fee amount 921 922 if (class_exists('Automattic\WooCommerce\Utilities\OrderUtil') && 923 OrderUtil::custom_orders_table_usage_is_enabled()) { 924 // HPOS usage is enabled. 925 $order->update_meta_data('_routeapp_route_charge', $insurance_amount); 926 $order->update_meta_data('_routeapp_route_protection', $insurance_selected); 927 $order->save(); 928 } else { 929 // Traditional CPT-based orders are in use. 930 update_post_meta($order->get_id(), '_routeapp_route_charge', $insurance_amount); 931 update_post_meta($order->get_id(), '_routeapp_route_protection', $insurance_selected); 932 } 925 $updated |= $this->updateRouteOrderMetaData( $order, $is_hpos, '_routeapp_route_charge', $insurance_amount ); 926 $updated |= $this->updateRouteOrderMetaData( $order, $is_hpos, '_routeapp_route_protection', true ); 933 927 } 934 928 } … … 941 935 942 936 } 943 944 if ( class_exists('Automattic\WooCommerce\Utilities\OrderUtil') 945 && OrderUtil::custom_orders_table_usage_is_enabled() ) { 946 // HPOS usage is enabled. 947 $order->update_meta_data('_routeapp_quote', $cached['body'] ); 948 949 //save to order the configuration selected regarding order statuses 950 $order->update_meta_data('_routeapp_included_order_statuses', json_encode($acceptedOrderStatuses)); 951 $order->update_meta_data( '_routeapp_cancel_order_statuses', json_encode($acceptedCanceledStatuses)); 952 953 $order->save(); 954 } else { 955 // Traditional CPT-based orders are in use. 956 update_post_meta( $order->get_id(), '_routeapp_quote', $cached['body'] ); 957 //save to order the configuration selected regarding order statuses 958 update_post_meta( $order->get_id(), '_routeapp_included_order_statuses', json_encode($acceptedOrderStatuses)); 959 update_post_meta( $order->get_id(), '_routeapp_cancel_order_statuses', json_encode($acceptedCanceledStatuses)); 960 } 937 $updated |= $this->updateRouteOrderMetaData( $order, $is_hpos, '_routeapp_quote', $cached['body'] ); 961 938 962 939 //clear cache! … … 967 944 } 968 945 969 //Update route included order statuses and route cancel order statuses when the order is created by the admin page without route fee 970 if(is_admin()){ 971 $this->updateRouteIncludedOrderStatusMetaFields( $order ); 972 } 946 //Add orders status meta data 947 $acceptedOrderStatuses = get_option('routeapp_included_order_statuses') ? get_option('routeapp_included_order_statuses') : []; 948 $acceptedCanceledStatuses = get_option('routeapp_cancel_order_statuses') ? get_option('routeapp_cancel_order_statuses') : []; 949 950 $updated |= $this->updateRouteOrderMetaData( $order, $is_hpos, '_routeapp_included_order_statuses', $acceptedOrderStatuses ); 951 $updated |= $this->updateRouteOrderMetaData( $order, $is_hpos, '_routeapp_cancel_order_statuses', $acceptedCanceledStatuses ); 952 953 // Save order if there is any update 954 if ($updated && $is_hpos) { 955 $order->save(); 956 } 973 957 } 974 958 … … 1734 1718 1735 1719 /** 1736 * @param $order1720 * Update order meta only if changed (HPOS & CPT safe) 1737 1721 * 1738 * @return void1722 * @return bool True if meta changed 1739 1723 */ 1740 public function updateRouteIncludedOrderStatusMetaFields( $order ): void { 1724 public function updateRouteOrderMetaData( 1725 WC_Order $order, 1726 bool $is_hpos, 1727 string $meta_key, 1728 $meta_value 1729 ): bool { 1741 1730 try { 1742 $acceptedOrderStatuses = get_option( 'routeapp_included_order_statuses' ) ? get_option( 'routeapp_included_order_statuses' ) : []; 1743 $acceptedCanceledStatuses = get_option( 'routeapp_cancel_order_statuses' ) ? get_option( 'routeapp_cancel_order_statuses' ) : []; 1744 1745 if ( class_exists( 'Automattic\WooCommerce\Utilities\OrderUtil' ) 1746 && OrderUtil::custom_orders_table_usage_is_enabled() ) { 1747 //save to order the configuration selected regarding order statuses 1748 $order->update_meta_data( '_routeapp_included_order_statuses', json_encode( $acceptedOrderStatuses ) ); 1749 $order->update_meta_data( '_routeapp_cancel_order_statuses', json_encode( $acceptedCanceledStatuses ) ); 1750 $order->save(); 1751 } else { 1752 update_post_meta( $order->get_id(), '_routeapp_included_order_statuses', json_encode( $acceptedOrderStatuses ) ); 1753 update_post_meta( $order->get_id(), '_routeapp_cancel_order_statuses', json_encode( $acceptedCanceledStatuses ) ); 1731 if ( ! $order || empty( $meta_key ) ) { 1732 return false; 1754 1733 } 1734 1735 $normalized = is_scalar( $meta_value ) 1736 ? (string) $meta_value 1737 : wp_json_encode( $meta_value ); 1738 1739 if ( $is_hpos ) { 1740 $current = $order->get_meta( $meta_key, true ); 1741 $current = is_scalar( $current ) ? (string) $current : wp_json_encode( $current ); 1742 1743 1744 if ( (string) $current === (string) $normalized ) { 1745 return false; 1746 } 1747 1748 $order->update_meta_data( $meta_key, $normalized ); 1749 return true; 1750 1751 } 1752 1753 $order_id = $order->get_id(); 1754 $current = get_post_meta( $order_id, $meta_key, true ); 1755 $current = is_scalar( $current ) ? (string) $current : wp_json_encode( $current ); 1756 1757 1758 if ( (string) $current === (string) $normalized ) { 1759 return false; 1760 } 1761 1762 update_post_meta( $order_id, $meta_key, $normalized ); 1763 return true; 1764 1755 1765 } catch ( Exception $e ) { 1756 // Log the exception and ensure the application flow continues 1757 error_log( "An error occurred while updating Route order status meta fields: " . $e->getMessage() ); 1766 error_log( 1767 'RouteApp: error updating order meta (' . $meta_key . '): ' . $e->getMessage() 1768 ); 1769 return false; 1758 1770 } 1759 1771 } -
routeapp/trunk/readme.txt
r3433867 r3443546 6 6 Requires at least: 4.0 7 7 Tested up to: 6.7.1 8 Stable tag: 2.2.3 38 Stable tag: 2.2.34 9 9 Requires PHP: 5.6 10 10 License: GPLv2 or later … … 106 106 107 107 == Changelog == 108 109 = 2.2.34 = 110 * Fix Route order metadata reliability and prevent duplicate order updates 108 111 109 112 = 2.2.33 = -
routeapp/trunk/routeapp.php
r3433867 r3443546 10 10 * Plugin URI: https://route.com/for-merchants/ 11 11 * 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.3 312 * Version: 2.2.34 13 13 * Author: Route 14 14 * Author URI: https://route.com/ … … 26 26 * Currently plugin version. 27 27 */ 28 define( 'ROUTEAPP_VERSION', '2.2.3 3' );28 define( 'ROUTEAPP_VERSION', '2.2.34' ); 29 29 30 30 /**
Note: See TracChangeset
for help on using the changeset viewer.