PluginProbe
MakeCommerce for WooCommerce / 3.3.1
MakeCommerce for WooCommerce v3.3.1
4.1.0 4.0.8 trunk 1.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.2 All 96 releases
← All changes | shipping/order.php +40 -107 trunk3.3.1 View file →
@@ -29,20 +29,14 @@
29 29 *
30 30 * @since 3.0.0
31 31 */
32 32 public function define_hooks() {
33 +
33 34 $this->loader->add_filter( 'woocommerce_order_details_after_customer_details', $this, 'parcel_machine_details' );
34 35 $this->loader->add_filter( 'woocommerce_admin_order_data_after_shipping_address', $this, 'parcel_machine_changing', 10, 1 );
35 36 $this->loader->add_filter( 'manage_shop_order_posts_custom_column', $this, 'shipping_method_order_view', 3 );
36 37 $this->loader->add_filter( 'woocommerce_email_customer_details_fields', $this, 'shipping_email_details', 10, 3 );
37 38 $this->loader->add_filter( 'restrict_manage_posts', $this, 'filter_orders' );
38 -
39 - // HPOS Add shipping method filtering selectbox to Woo orders page as well
40 - $this->loader->add_filter( 'woocommerce_order_list_table_restrict_manage_orders', $this, 'hpos_filter_orders' );
41 - // HPOS Add shipping method filtering functionality
42 - $this->loader->add_filter( 'woocommerce_order_query_args', $this, 'order_filter_by_shipping_method' );
43 - // HPOS Add bulk actions
44 - $this->loader->add_filter( 'bulk_actions-woocommerce_page_wc-orders', $this, 'mc_bulk_actions' );
45 39 }
46 40
47 41 /**
48 42 * Add parcel machine information to order view (Customer)
@@ -50,9 +44,9 @@
50 44 * @since 3.0.0
51 45 */
52 46 public function parcel_machine_details( $order ) {
53 47
54 - $machine_id = $order->get_meta( '_parcel_machine', true );
48 + $machine_id = get_post_meta( $order->get_id(), '_parcel_machine', true );
55 49
56 50 if ( empty( $machine_id ) ) {
57 51 return;
58 52 }
@@ -87,9 +81,10 @@
87 81 * @since 3.0.0
88 82 */
89 83 public function parcel_machine_changing( $order ) {
90 84
91 - $machine_id = $order->get_meta( '_parcel_machine', true );
85 + $order_id = $order->get_id();
86 + $machine_id = get_post_meta( $order_id, '_parcel_machine', true );
92 87 $carrier = '';
93 88
94 89 if ( !empty( $machine_id ) ) {
95 90
@@ -133,10 +128,10 @@
133 128 $presetArray = \MakeCommerce\Shipping\Method\ParcelMachine\LPExpress::get_lp_express_presets();
134 129 // Default setting
135 130 $default = get_option( 'mk_lpexpress_template' );
136 131 // If order has been edited and a template has been chosen
137 - if ( !empty( $order->get_meta( '_mk_parcel_template', true ) ) ) {
138 - $template = $order->get_meta( '_mk_parcel_template', true );
132 + if ( !empty( get_post_meta( $order_id, '_mk_parcel_template' ) ) ) {
133 + $template = get_post_meta( $order_id, '_mk_parcel_template' )[0];
139 134 } else {
140 135 // Otherwise use the default preset
141 136 $template = $default;
142 137 }
@@ -173,11 +168,11 @@
173 168 //can be an empty div in case of other shipping methods
174 169 echo '<div class="address">';
175 170 }
176 171
177 - $shipment_id = $order->get_meta( '_parcel_machine_shipment_id', true );
178 - $shipment_id_error = $order->get_meta( '_parcel_machine_error', true );
179 - $shipment_manifest = $order->get_meta( '_parcel_machine_manifest', true );
172 + $shipment_id = get_post_meta( $order_id, '_parcel_machine_shipment_id', true );
173 + $shipment_id_error = get_post_meta( $order_id, '_parcel_machine_error', true );
174 + $shipment_manifest = get_post_meta( $order_id, '_parcel_machine_manifest', true );
180 175
181 176 $shippingMethod["method_title"] = '';
182 177
183 178 //currently the only delivery time option exists for smartpost courier shipping method.
@@ -184,9 +179,10 @@
184 179 //only one shipping method, get it easily from array with foreach
185 180 foreach ( $order->get_shipping_methods() as $shippingMethod) {
186 181
187 182 if ( $shippingMethod["method_id"] == "courier_smartpost" && !$shipment_id_error ) {
188 - $delivery_time = $order->get_meta( '_delivery_time', true );
183 +
184 + $delivery_time = get_post_meta( $order_id, '_delivery_time', true );
189 185
190 186 switch ( $delivery_time ) {
191 187 case '1':
192 188 echo '<p><strong>'.__( 'Delivery time', 'wc_makecommerce_domain' ).'</strong> - '.__( 'Any time', 'wc_makecommerce_domain' ).'</p>';
@@ -208,14 +204,13 @@
208 204 $carrier = $this->get_order_shipment_carrier( $order );
209 205 }
210 206
211 207 if ( $carrier === 'lp_express_lt' ) {
212 - $shipment_id = $order->get_meta( '_parcel_machine_shipment_barcode', true );
208 + $shipment_id = get_post_meta( $order_id, '_parcel_machine_shipment_barcode', true );
213 209 $carrier = "lpexpress";
214 210 }
215 211
216 - $theLink = $this->get_tracking_link( $carrier, $order, $shipment_id, true );
217 -
212 + $theLink = $this->get_tracking_link( $carrier, $order_id, $shipment_id, true );
218 213 if ( $carrier != "" && $theLink != "" ) {
219 214 $trackinglink .= ' ('. ucfirst( $shippingMethod["method_title"] ) .'): <br/> <a target="_blank" href="' . $theLink . '">' . $shipment_id . '</a>';
220 215 } else {
221 216 $trackinglink .= ': <br/>'.$shipment_id;
@@ -242,40 +237,41 @@
242 237 */
243 238 public function shipping_method_order_view( $column ) {
244 239
245 240 global $post, $woocommerce, $the_order;
246 -
247 - if ( !$the_order ) {
241 +
242 + if ( !$the_order ) {
248 243 return;
249 244 }
250 245
251 - $the_order_id = $the_order->get_id();
252 -
246 + $the_order_id = $the_order->get_id();
247 +
253 248 if ( empty( $the_order ) || $the_order_id != $post->ID ) {
254 249
255 250 $the_order = wc_get_order( $post->ID );
256 251 }
252 +
253 + if ( $column === 'shipping_address' ) {
257 254
258 - if ( $column === 'shipping_address' ) {
255 + $machine_id = get_post_meta( $the_order_id, '_parcel_machine', true );
256 + $shipment_id = get_post_meta( $the_order_id, '_parcel_machine_shipment_id', true );
257 + $shipment_id_error = get_post_meta( $the_order_id, '_parcel_machine_error', true );
258 + $identifier = get_post_meta( $the_order_id, '_lp_express_cart_identifier', true );
259 + $barcode = get_post_meta( $the_order_id, '_parcel_machine_shipment_barcode', true );
259 260
260 - $shipment_id = $the_order->get_meta( '_parcel_machine_shipment_id', true );
261 - $shipment_id_error = $the_order->get_meta( '_parcel_machine_error', true );
262 - $identifier = $the_order->get_meta( '_lp_express_cart_identifier', true );
263 - $barcode = $the_order->get_meta( '_parcel_machine_shipment_barcode', true );
261 + // LP Express
262 + if ( !empty( $identifier ) && !empty( $barcode ) ) {
263 + $shipment_id = $barcode;
264 + }
264 265
265 - // LP Express
266 - if ( !empty( $identifier ) && !empty( $barcode ) ) {
267 - $shipment_id = $barcode;
268 - }
269 -
270 - if ( $shipment_id ) {
271 -
272 - echo __( 'Shipment tracking code', 'wc_makecommerce_domain' ) . ': ' . $shipment_id . '<br/>';
273 - echo '<span class="has_shipment_id"></span>';
274 - } else if ( $shipment_id_error ) {
266 + if ( $shipment_id ) {
267 +
268 + echo __( 'Shipment tracking code', 'wc_makecommerce_domain' ) . ': ' . $shipment_id . '<br/>';
269 + echo '<span class="has_shipment_id"></span>';
270 + } else if ( $shipment_id_error ) {
275 271 echo '<span style="color: red;">'.__( 'Package shipment generation error:', 'wc_makecommerce_domain' ) . '</span><br/>' .$shipment_id_error;
276 272 }
277 - }
273 + }
278 274 }
279 275
280 276 /**
281 277 * Fires before the Filter button on the Posts and Pages list tables.
@@ -295,34 +291,9 @@
295 291 echo '<select name="_shipping_method" id="shipping_type" class="enhanced">';
296 292 echo '<option value="">'.__( '-- filter by shipping method', 'wc_makecommerce_domain' ) . '</option>';
297 293
298 294 foreach ( $methods as $method ) {
299 - echo '<option value="'.$method->id.'"'.($selected_method === $method->id ? ' selected="selected"' : '').'>'.$method->get_method_title().'</option>';
300 - }
301 295
302 - echo '</select>';
303 - }
304 - }
305 -
306 - /**
307 - * Fires before the Filter button on the orders page
308 - * Allows filtering of orders by shipping method
309 - *
310 - * @since 3.4.0
311 - */
312 - public function hpos_filter_orders() {
313 -
314 - if ( $_GET['page'] == 'wc-orders' ) {
315 -
316 - $selected_method = !empty( $_REQUEST['_shipping_method'] ) ? $_REQUEST['_shipping_method'] : false;
317 - $methods = WC()->shipping->load_shipping_methods();
318 -
319 - echo '<select name="_shipping_method" id="shipping_type" class="enhanced">';
320 - echo '<option value="">'.__( '-- filter by shipping method', 'wc_makecommerce_domain' ) . '</option>';
321 -
322 - foreach ( $methods as $method ) {
323 - // Can not filter by methods which are not provided by MK
324 - if ( !$method instanceof \MakeCommerce\Shipping\Method ) continue;
325 296 echo '<option value="'.$method->id.'"'.($selected_method === $method->id ? ' selected="selected"' : '').'>'.$method->get_method_title().'</option>';
326 297 }
327 298
328 299 echo '</select>';
@@ -350,18 +321,14 @@
350 321 *
351 322 * @since 3.0.0
352 323 */
353 324 public function shipping_email_details( $fields, $sent_to_admin, $order ) {
354 - // No mc metadata without calling the wc_get_order again
355 - $order = wc_get_order($order->get_id());
356 325
357 - if ( ! $order ) {return $fields;}
358 -
359 326 //check if makecommerce shipping has been used
360 327 //add tracking information (if possible)
361 - $shipment_id = $order->get_meta( "_parcel_machine_shipment_id", true );
328 + $shipment_id = get_post_meta( $order->get_id(), "_parcel_machine_shipment_id", true );
362 329
363 - $machine_id = $order->get_meta( '_parcel_machine', true );
330 + $machine_id = get_post_meta( $order->get_id(), '_parcel_machine', true );
364 331
365 332 $machine = "";
366 333 $carrier = "";
367 334
@@ -414,15 +381,16 @@
414 381 $fields[] = array( 'label' => __( 'Parcel machine', 'wc_makecommerce_domain' ).' ('.ucfirst( $carrier ).')', 'value' => $machine['name'].' - '.$machine['address']);
415 382 }
416 383 }
417 384
418 - $shipment_id_error = $order->get_meta( '_parcel_machine_error', true );
385 + $shipment_id_error = get_post_meta( $order->get_id(), '_parcel_machine_error', true );
419 386
420 387 //currently the only delivery time option exists for smartpost courier shipping method.
421 388 foreach ( $order->get_shipping_methods() as $shippingMethod ) {
422 389
423 390 if ( $shippingMethod["method_id"] == "courier_smartpost" ) {
424 - $delivery_time = $order->get_meta( '_delivery_time', true );
391 +
392 + $delivery_time = get_post_meta( $order->get_id(), '_delivery_time', true );
425 393
426 394 if ( !$shipment_id_error ) {
427 395
428 396 if ( $delivery_time === '1' ) {
@@ -449,9 +417,9 @@
449 417 if ( $carrier == "" ) {
450 418 $carrier = $this->get_order_shipment_carrier( $order );
451 419 }
452 420
453 - $href = $this->get_tracking_link( $carrier, $order, $shipment_id );
421 + $href = $this->get_tracking_link( $carrier, $order->get_id(), $shipment_id );
454 422
455 423 if ( $href != "" ) {
456 424 $fields[] = array( 'label' => __( 'Shipment tracking info', 'wc_makecommerce_domain' ).' ('.$carrier.')', 'value' => "<a target='_blank' title='".__( 'Shipment tracking code', 'wc_makecommerce_domain' )."' href='".$href."'>".$href."</a>" );
457 425 } else {
@@ -460,40 +428,5 @@
460 428 }
461 429
462 430 return $fields;
463 431 }
464 -
465 - /**
466 - * Adds bulk actions to orders page without JS
467 - * Works with HPOS enabled
468 - *
469 - * @since 3.4.0
470 - */
471 - public function mc_bulk_actions( $actions ) {
472 - $actions['parcel_machine_register_orders'] = __( 'Register parcel machine shipments', 'wc_makecommerce_domain' );
473 - $actions['parcel_machine_print_labels'] = __( 'Print parcel machine labels', 'wc_makecommerce_domain' );
474 - return $actions;
475 - }
476 -
477 - /**
478 - * Filters orders by _mc_shipping_method meta key
479 - * Relies on hpos_filter_orders()
480 - * Works with HPOS enabled
481 - *
482 - * @since 3.4.0
483 - */
484 - public function order_filter_by_shipping_method( $args ) {
485 -
486 - if ( is_admin() && !empty( $_REQUEST['_shipping_method'] ) && $_GET['page'] == 'wc-orders' ) {
487 - $shipping_method = sanitize_text_field( $_REQUEST['_shipping_method'] );
488 -
489 - $args['meta_query'] = [
490 - [
491 - 'key' => '_mc_shipping_method',
492 - 'value' => $shipping_method
493 - ]
494 - ];
495 - }
496 -
497 - return $args;
498 - }
499 432 }