PluginProbe
Route ‑ Shipping Protection / 2.4.18
Route ‑ Shipping Protection v2.4.18
2.4.19 2.4.18 2.4.17 2.4.16 2.4.15 2.4.14 2.4.13 2.4.12 2.4.11 2.4.10 2.4.9 2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.2.4 2.2.5 2.2.6 2.2.8 2.2.9 2.3.0 2.3.1 All 153 releases
← All changes | includes/class-routeapp-woocommerce.php +65 -19 2.2.9 → 2.4.18 View file →
@@ -20,16 +20,22 @@
20 20 }
21 21
22 22 public function init() {
23 23
24 - if ($this->routeapp_route_enabled_extra_columns()) {
25 - add_filter( 'manage_edit-shop_order_columns', array( $this, 'routeapp_add_order_route_columns_header' ), 20 );
26 - add_action( 'manage_shop_order_posts_custom_column', array( $this, 'routeapp_manage_route_charge_posts_custom_column' ) );
27 - add_action( 'restrict_manage_posts', array( $this, 'routeapp_display_admin_shop_order_route_protection_filter' ) );
28 - add_action( 'pre_get_posts', array( $this, 'routeapp_process_admin_shop_order_route_protection' ) );
29 - }
30 - }
24 + if ($this->routeapp_route_enabled_extra_columns()) {
25 + add_filter( 'manage_edit-shop_order_columns', array( $this, 'routeapp_add_order_route_columns_header' ), 20 );
26 + add_action( 'manage_shop_order_posts_custom_column', array( $this, 'routeapp_manage_route_charge_posts_custom_column' ));
27 + add_action( 'restrict_manage_posts', array( $this, 'routeapp_display_admin_shop_order_route_protection_filter' ) );
28 + add_action( 'pre_get_posts', array( $this, 'routeapp_process_admin_shop_order_route_protection' ));
31 29
30 + add_action( 'manage_woocommerce_page_wc-orders_custom_column', array( $this, 'routeapp_manage_route_charge_posts_custom_column_new' ) , 99, 2 );
31 + add_action( 'manage_shop_order_custom_column', array( $this, 'routeapp_manage_route_charge_posts_custom_column_new' ) , 99, 2 );
32 +
33 + add_filter( 'manage_woocommerce_page_wc-orders_columns', array( $this, 'routeapp_add_order_route_columns_header' ), 20 );
34 +
35 + }
36 + }
37 +
32 38 /**
33 39 * Add their respective Route Protection and Route Charge columns after order date
34 40 *
35 41 * @since 1.0.3
@@ -49,24 +55,47 @@
49 55 return $new_columns;
50 56 }
51 57
52 58 /**
59 + * Add their respective Route Protection and Route Charge values.
60 + *
61 + * @since 1.0.3
62 + * @return void
63 + */
64 + public function routeapp_manage_route_charge_posts_custom_column( $column ) {
65 + global $post;
66 + $order = wc_get_order( $post->ID );
67 +
68 + if ( $column === 'route_charge' ) {
69 + echo wc_price( $this->routeapp_get_route_charge_fee( $order ), array( 'currency' => $order->get_currency() ) );
70 + } else if ( $column === 'route_protection' ) {
71 + echo $this->routeapp_order_has_route_protection_fee( $order ) ? "Yes" : "No";
72 + }
73 + }
74 +
75 + /**
53 76 * Add their respective Route Protection and Route Charge values.
54 77 *
55 78 * @since 1.0.3
56 79 * @return void
57 80 */
58 - public function routeapp_manage_route_charge_posts_custom_column( $column ) {
59 - global $post;
60 - $order = wc_get_order( $post->ID );
81 + public function routeapp_manage_route_charge_posts_custom_column_new( $column, $orderParam ) {
82 + global $post;
61 83
62 - if ( $column === 'route_charge' ) {
63 - echo wc_price( $this->routeapp_get_route_charge_fee( $order ), array( 'currency' => $order->get_currency() ) );
64 - } else if ( $column === 'route_protection' ) {
65 - echo $this->routeapp_order_has_route_protection_fee( $order ) ? "Yes" : "No";
66 - }
67 - }
84 + // Check if $orderParam is set and not null
85 + if ( isset( $orderParam ) && ! is_null( $orderParam ) ) {
86 + $order = $orderParam; // Get the order using $orderParam if it's valid
87 + } else {
88 + $order = wc_get_order( $post->ID ); // Fallback to global $post if $orderParam is not set
89 + }
68 90
91 + if ( $column === 'route_charge' ) {
92 + echo wc_price( $this->routeapp_get_route_charge_fee( $order ), array( 'currency' => $order->get_currency() ) );
93 + } else if ( $column === 'route_protection' ) {
94 + echo $this->routeapp_order_has_route_protection_fee( $order ) ? "Yes" : "No";
95 + }
96 + }
97 +
69 98 /**
70 99 * Returns the order's post_meta and checks the Route Charge price
71 100 *
72 101 * @since 1.0.3
@@ -73,8 +102,9 @@
73 102 * @param $order Order's woocommerce object
74 103 * @return float $price
75 104 */
76 105 public function routeapp_get_route_charge_fee( $order ) {
106 + global $post;
77 107 $price = "";
78 108 if ( class_exists('Automattic\WooCommerce\Utilities\OrderUtil')
79 109 && OrderUtil::custom_orders_table_usage_is_enabled() ) {
80 110 // HPOS usage is enabled.
@@ -79,10 +109,13 @@
79 109 && OrderUtil::custom_orders_table_usage_is_enabled() ) {
80 110 // HPOS usage is enabled.
81 111 $price = $order->get_meta('_routeapp_route_charge');
82 112 } else {
83 - // Traditional CPT-based orders are in use.
84 - $price = get_post_meta($order->get_id(), '_routeapp_route_charge', true);
113 + $orderData = wc_get_order( $post->ID );
114 + if ($orderData) {
115 + // Traditional CPT-based orders are in use.
116 + $price = get_post_meta($order->get_id(), '_routeapp_route_charge', true);
117 + }
85 118 }
86 119
87 120
88 121 if ( $price === "" ) {
@@ -99,9 +132,22 @@
99 132 * @param $order Order's woocommerce object
100 133 * @return bool
101 134 */
102 135 public function routeapp_order_has_route_protection_fee( $order ) {
103 - $route_protection = get_post_meta($order->get_id(), '_routeapp_route_protection', true);
136 + global $post;
137 + $route_protection = "0";
138 + if ( class_exists('Automattic\WooCommerce\Utilities\OrderUtil')
139 + && OrderUtil::custom_orders_table_usage_is_enabled() ) {
140 + // HPOS usage is enabled.
141 + $route_protection = $order->get_meta('_routeapp_route_protection');
142 + } else {
143 + $orderData = wc_get_order( $post->ID );
144 + if ($orderData) {
145 + // Traditional CPT-based orders are in use.
146 + $route_protection = get_post_meta($orderData->get_id(), '_routeapp_route_protection', true);
147 + }
148 + }
149 +
104 150 return $route_protection === "1";
105 151 }
106 152
107 153 /**