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 +75 -18 2.2.6 → 2.4.18 View file →
@@ -9,8 +9,10 @@
9 9 * @package Routeapp
10 10 * @subpackage Routeapp/includes
11 11 */
12 12
13 +use Automattic\WooCommerce\Utilities\OrderUtil;
14 +
13 15 class Routeapp_Woocommerce
14 16 {
15 17
16 18 public function __construct() {
@@ -18,16 +20,22 @@
18 20 }
19 21
20 22 public function init() {
21 23
22 - if ($this->routeapp_route_enabled_extra_columns()) {
23 - add_filter( 'manage_edit-shop_order_columns', array( $this, 'routeapp_add_order_route_columns_header' ), 20 );
24 - add_action( 'manage_shop_order_posts_custom_column', array( $this, 'routeapp_manage_route_charge_posts_custom_column' ) );
25 - add_action( 'restrict_manage_posts', array( $this, 'routeapp_display_admin_shop_order_route_protection_filter' ) );
26 - add_action( 'pre_get_posts', array( $this, 'routeapp_process_admin_shop_order_route_protection' ) );
27 - }
28 - }
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 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 +
30 38 /**
31 39 * Add their respective Route Protection and Route Charge columns after order date
32 40 *
33 41 * @since 1.0.3
@@ -47,24 +55,47 @@
47 55 return $new_columns;
48 56 }
49 57
50 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 + /**
51 76 * Add their respective Route Protection and Route Charge values.
52 77 *
53 78 * @since 1.0.3
54 79 * @return void
55 80 */
56 - public function routeapp_manage_route_charge_posts_custom_column( $column ) {
57 - global $post;
58 - $order = wc_get_order( $post->ID );
81 + public function routeapp_manage_route_charge_posts_custom_column_new( $column, $orderParam ) {
82 + global $post;
59 83
60 - if ( $column === 'route_charge' ) {
61 - echo wc_price( $this->routeapp_get_route_charge_fee( $order ), array( 'currency' => $order->get_currency() ) );
62 - } else if ( $column === 'route_protection' ) {
63 - echo $this->routeapp_order_has_route_protection_fee( $order ) ? "Yes" : "No";
64 - }
65 - }
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 + }
66 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 +
67 98 /**
68 99 * Returns the order's post_meta and checks the Route Charge price
69 100 *
70 101 * @since 1.0.3
@@ -71,9 +102,22 @@
71 102 * @param $order Order's woocommerce object
72 103 * @return float $price
73 104 */
74 105 public function routeapp_get_route_charge_fee( $order ) {
75 - $price = get_post_meta($order->get_id(), '_routeapp_route_charge', true);
106 + global $post;
107 + $price = "";
108 + if ( class_exists('Automattic\WooCommerce\Utilities\OrderUtil')
109 + && OrderUtil::custom_orders_table_usage_is_enabled() ) {
110 + // HPOS usage is enabled.
111 + $price = $order->get_meta('_routeapp_route_charge');
112 + } else {
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 + }
118 + }
119 +
76 120
77 121 if ( $price === "" ) {
78 122 $price = 0;
79 123 }
@@ -88,9 +132,22 @@
88 132 * @param $order Order's woocommerce object
89 133 * @return bool
90 134 */
91 135 public function routeapp_order_has_route_protection_fee( $order ) {
92 - $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 +
93 150 return $route_protection === "1";
94 151 }
95 152
96 153 /**