PluginProbe
PostNL for WooCommerce / 3.1.7
PostNL for WooCommerce v3.1.7
5.9.12 5.9.11 5.9.10 5.9.9 5.9.8 5.9.7 5.9.6 trunk 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 3.1.4 3.1.5 3.1.6 3.1.7 4.0.0 4.0.1 4.0.2 4.3.2 4.3.3 4.4.0 4.4.1 All 72 releases
woo-postnl / includes / class-wcmp-admin.php

class-wcmp-admin.php in PostNL for WooCommerce 3.1.7, at includes/class-wcmp-admin.php

657 lines 26.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use WPO\WC\PostNL\Compatibility\WC_Core as WCX;
4 use WPO\WC\PostNL\Compatibility\Order as WCX_Order;
5 use WPO\WC\PostNL\Compatibility\Product as WCX_Product;
6
7 if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
8
9 if ( ! class_exists('WooCommerce_PostNL_Admin')) :
10
11 /**
12 * Admin options, buttons & data
13 */
14 class WooCommerce_PostNL_Admin {
15
16 function __construct() {
17 add_action('woocommerce_admin_order_actions_end', array($this, 'order_list_shipment_options'), 9999);
18 add_action('admin_footer', array($this, 'bulk_actions'));
19
20 add_action('admin_footer', array($this, 'offset_dialog'));
21 add_action('woocommerce_admin_order_actions_end', array($this, 'admin_wc_actions'), 20);
22 add_action('add_meta_boxes_shop_order', array($this, 'shop_order_metabox'));
23 add_action('woocommerce_admin_order_data_after_shipping_address', array($this, 'single_order_shipment_options'));
24
25 add_action('wp_ajax_wcmp_save_shipment_options', array($this, 'save_shipment_options_ajax'));
26 add_action('wp_ajax_wcmp_get_shipment_summary_status', array($this, 'order_list_ajax_get_shipment_summary'));
27
28 // HS code in product shipping options tab
29 add_action('woocommerce_product_options_shipping', array($this, 'product_hs_code_field'));
30 add_action('woocommerce_process_product_meta', array($this, 'product_hs_code_field_save'));
31
32 // Add barcode in order grid
33 add_filter('manage_edit-shop_order_columns', array($this, 'barcode_add_new_order_admin_list_column'), 10, 1);
34 add_action('manage_shop_order_posts_custom_column', array($this, 'barcode_add_new_order_admin_list_column_content'), 10, 2);
35 }
36
37 public function order_list_shipment_options($order, $hide = true) {
38 $shipping_country = WCX_Order::get_prop($order, 'shipping_country');
39 if ( ! WooCommerce_PostNL()->export->is_postnl_destination($shipping_country)) {
40 return;
41 }
42 $order_id = WCX_Order::get_id($order);
43 $shipment_options = WooCommerce_PostNL()->export->get_options($order);
44 $postnl_options_extra = WCX_Order::get_meta($order, '_postnl_shipment_options_extra');
45 $package_types = WooCommerce_PostNL()->export->get_package_types();
46 $recipient = WooCommerce_PostNL()->export->get_recipient($order);
47
48 // get shipment data (exclude concepts = true)
49 $consignments = $this->get_order_shipments($order, true);
50
51 $style = $hide ? 'style="display:none"' : '';
52 // if we have shipments, then we show status & link to Track & Trace, settings under i
53 if ( ! empty($consignments)) {
54 // only use last shipment
55 $last_shipment = array_pop($consignments);
56 $last_shipment_id = $last_shipment['shipment_id'];
57 ?>
58 <div class="wcmp_shipment_summary" <?php echo $style; ?>>
59 <?php $this->show_order_delivery_options($order); ?>
60 <a class="wcmp_show_shipment_summary"><span class="encircle wcmp_show_shipment_summary">i</span></a>
61 <div class="wcmp_shipment_summary_list" data-loaded="" data-shipment_id="<?php echo $last_shipment_id; ?>" data-order_id="<?php echo $order_id; ?>" style="display: none;">
62 <img src="<?php echo WooCommerce_PostNL()->plugin_url() . '/assets/img/wpspin_light.gif'; ?>" class="wcmp_spinner" />
63 </div>
64 </div>
65 <?php
66 } else {
67 ?>
68 <div class="wcmp_shipment_options" <?php echo $style; ?>>
69 <?php $this->show_order_delivery_options($order); ?>
70 </div>
71 <?php
72 }
73
74 ?>
75 <div class="wcmp_shipment_options" <?php echo $style; ?>>
76 <?php printf('<a href="#" class="wcmp_show_shipment_options"><span class="wcpm_package_type">%s</span> &#x25BE;</a>', $package_types[$shipment_options['package_type']]); ?>
77 <div class="wcmp_shipment_options_form" style="display: none;">
78 <?php include('views/wcmp-order-shipment-options.php'); ?>
79 </div>
80 </div>
81 <?php
82 }
83
84 /**
85 * Get shipment status + Track & Trace link via AJAX
86 */
87 public function order_list_ajax_get_shipment_summary() {
88 check_ajax_referer('wc_postnl', 'security');
89 extract($_POST); // order_id, shipment_id
90 $order = wc_get_order($order_id);
91 $shipment = WooCommerce_PostNL()->export->get_shipment_data($shipment_id, $order);
92 if ( ! empty($shipment['tracktrace'])) {
93 $order_has_shipment = true;
94 $tracktrace_url = $this->getTrackTraceUrl($order_id, $shipment['tracktrace']);
95 }
96 $package_types = WooCommerce_PostNL()->export->get_package_types();
97
98 include('views/wcmp-order-shipment-summary.php');
99 die();
100 }
101
102 public function order_list_return_shipment_options($order, $hide = true) {
103 $shipping_country = WCX_Order::get_prop($order, 'shipping_country');
104 if ($shipping_country != 'NL' && ! WooCommerce_PostNL()->export->is_eu_country($shipping_country)) {
105 return;
106 }
107
108 $style = $hide ? 'style="display:none"' : '';
109 ?>
110 <div class="wcmp_shipment_options_form return_shipment" <?php echo $style; ?>>
111 <?php include('views/wcmp-order-return-shipment-options.php'); ?>
112 </div>
113 <?php
114 }
115
116 /**
117 * Add export option to bulk action drop down menu
118 * Using Javascript until WordPress core fixes: http://core.trac.wordpress.org/ticket/16031
119 * @access public
120 * @return void
121 */
122 public function bulk_actions() {
123 global $post_type;
124 $bulk_actions = array(
125 'wcmp_export' => __('PostNL: Prepare shipment', 'woocommerce-postnl'),
126 'wcmp_print' => __('PostNL: Print', 'woocommerce-postnl'),
127 'wcmp_export_print' => __('PostNL: Prepare & print shipment', 'woocommerce-postnl'),
128 );
129
130 if ('shop_order' == $post_type) {
131 ?>
132 <script type="text/javascript">
133 jQuery(document).ready(function() {
134 <?php foreach ($bulk_actions as $action => $title) { ?>
135 jQuery('<option>').val('<?php echo $action; ?>').html('<?php echo esc_attr($title); ?>').appendTo("select[name='action'], select[name='action2']");
136 <?php } ?>
137 });
138 </script>
139 <img src="<?php echo WooCommerce_PostNL()->plugin_url() . '/assets/img/wpspin_light.gif'; ?>" class="wcmp_bulk_spinner waiting" style="display:none;" />
140 <?php
141 }
142 }
143
144 /**
145 * Show dialog to choose print position (offset)
146 * @access public
147 * @return void
148 */
149 public function offset_dialog() {
150 global $post_type;
151 if ('shop_order' == $post_type) {
152 ?>
153 <div id="wcpostnl_offset_dialog" style="display:none;">
154 <?php _e('Labels to skip', 'woocommerce-postnl'); ?>:
155 <input type="text" size="2" class="wc_postnl_offset">
156 <img src="<?php echo WooCommerce_PostNL()->plugin_url() . '/assets/img/print-offset-icon.png'; ?>" id="wcpostnl-offset-icon" style="vertical-align: middle;">
157 <button class="button" style="display:none; margin-top: 4px"><?php _e('Print', 'woocommerce-postnl'); ?></button>
158 </div>
159 <?php
160 }
161 }
162
163 /**
164 * Add print actions to the orders listing
165 * Support wc > 3.3.0
166 * Call the function admin_order_actions for the same settings
167 *
168 * @param $order
169 */
170 public function admin_wc_actions($order) {
171 return $this->admin_order_actions($order);
172 }
173
174 /**
175 * Add print actions to the orders listing
176 */
177 public function admin_order_actions($order) {
178 if (empty($order)) {
179 return;
180 }
181
182 $shipping_country = WCX_Order::get_prop($order, 'shipping_country');
183 if ( ! WooCommerce_PostNL()->export->is_postnl_destination($shipping_country)) {
184 return;
185 }
186
187 $order_id = WCX_Order::get_id($order);
188
189 $listing_actions = array(
190 'add_shipment' => array(
191 'url' => wp_nonce_url(admin_url('admin-ajax.php?action=wc_postnl&request=add_shipment&order_ids=' . $order_id), 'wc_postnl'),
192 'img' => WooCommerce_PostNL()->plugin_url() . '/assets/img/postnl-up.png',
193 'alt' => esc_attr__('Export to PostNL', 'woocommerce-postnl'),
194 ),
195 'get_labels' => array(
196 'url' => wp_nonce_url(admin_url('admin-ajax.php?action=wc_postnl&request=get_labels&order_ids=' . $order_id), 'wc_postnl'),
197 'img' => WooCommerce_PostNL()->plugin_url() . '/assets/img/postnl-pdf.png',
198 'alt' => esc_attr__('Print PostNL label', 'woocommerce-postnl'),
199 ),
200 );
201
202 $consignments = $this->get_order_shipments($order);
203
204 if (empty($consignments)) {
205 unset($listing_actions['get_labels']);
206 }
207
208 $processed_shipments = $this->get_order_shipments($order, true);
209 if (empty($processed_shipments) || $shipping_country != 'NL') {
210 unset($listing_actions['add_return']);
211 }
212
213 $target = (isset(WooCommerce_PostNL()->general_settings['download_display'])
214 && WooCommerce_PostNL()->general_settings['download_display'] == 'display') ? 'target="_blank"'
215 : '';
216 $nonce = wp_create_nonce('wc_postnl');
217 foreach ($listing_actions as $action => $data) {
218 printf(
219 '<a href="%1$s" class="button tips postnl %2$s" alt="%3$s" data-tip="%3$s" data-order-id="%4$s" data-request="%2$s" data-nonce="%5$s" %6$s>',
220 $data['url'],
221 $action,
222 $data['alt'],
223 $order_id,
224 $nonce,
225 $target
226 );
227 ?>
228 <img src="<?php echo $data['img']; ?>" alt="<?php echo $data['alt']; ?>" style="width:17px; margin: 5px 3px; pointer-events: none;" class="wcmp_button_img"> </a>
229 <?php
230 }
231 ?>
232 <img src="<?php echo WooCommerce_PostNL()->plugin_url(
233 ) . '/assets/img/wpspin_light.gif'; ?>" style="width: 17px; margin: 5px 3px;" class="wcmp_spinner waiting" />
234 <?php
235 }
236
237 public function get_order_shipments($order, $exclude_concepts = false) {
238 if (empty($order)) {
239 return;
240 }
241
242 $consignments = WCX_Order::get_meta($order, '_postnl_shipments');
243 // fallback to legacy consignment data (v1.X)
244 if (empty($consignments)) {
245 if ($consignment_id = WCX_Order::get_meta($order, '_postnl_consignment_id')) {
246 $consignments = array(
247 array(
248 'shipment_id' => $consignment_id,
249 'tracktrace' => WCX_Order::get_meta($order, '_postnl_tracktrace'),
250 ),
251 );
252 } else {
253 if ($legacy_consignments = WCX_Order::get_meta($order, '_postnl_consignments')) {
254 $consignments = array();
255 foreach ($legacy_consignments as $consignment) {
256 if (isset($consignment['consignment_id'])) {
257 $consignments[] = array(
258 'shipment_id' => $consignment['consignment_id'],
259 'tracktrace' => $consignment['tracktrace'],
260 );
261 }
262 }
263 }
264 }
265 }
266
267 if (empty($consignments) || ! is_array($consignments)) {
268 return false;
269 }
270
271 if ( ! empty($consignments) && $exclude_concepts) {
272 foreach ($consignments as $key => $consignment) {
273 if (empty($consignment['tracktrace'])) {
274 unset($consignments[$key]);
275 }
276 }
277 }
278
279 return $consignments;
280 }
281
282 public function save_shipment_options_ajax() {
283 check_ajax_referer('wc_postnl', 'security');
284 extract($_POST);
285 parse_str($form_data, $form_data);
286 $order = WCX::get_order($order_id);
287
288 if (isset($form_data['postnl_options'][$order_id])) {
289 $shipment_options = $form_data['postnl_options'][$order_id];
290
291 // convert insurance option
292 if (isset($shipment_options['insured'])) {
293 unset($shipment_options['insured']);
294 $shipment_options['insurance'] = array(
295 'amount' => (int) $shipment_options['insured_amount'] * 100,
296 'currency' => 'EUR',
297 );
298 unset($shipment_options['insured_amount']);
299 }
300
301 // separate extra options
302 if (isset($shipment_options['extra_options'])) {
303 WCX_Order::update_meta_data(
304 $order,
305 '_postnl_shipment_options_extra',
306 $shipment_options['extra_options']
307 );
308 unset($shipment_options['extra_options']);
309 }
310
311 WCX_Order::update_meta_data($order, '_postnl_shipment_options', $shipment_options);
312 }
313
314 // Quit out
315 die();
316 }
317
318 /**
319 * Add the meta box on the single order page
320 */
321 public function shop_order_metabox() {
322 add_meta_box(
323 'postnl', //$id
324 __('PostNL', 'woocommerce-postnl'), //$title
325 array($this, 'create_box_content'), //$callback
326 'shop_order', //$post_type
327 'side', //$context
328 'default' //$priority
329 );
330 }
331
332 /**
333 * Callback: Create the meta box content on the single order page
334 */
335 public function create_box_content() {
336 global $post_id;
337 // get order
338 $order = WCX::get_order($post_id);
339 if ( ! $order) {
340 return;
341 }
342 $order_id = WCX_Order::get_id($order);
343
344 $shipping_country = WCX_Order::get_prop($order, 'shipping_country');
345 if ( ! WooCommerce_PostNL()->export->is_postnl_destination($shipping_country)) {
346 return;
347 }
348
349 // show buttons and check if WooCommerce > 3.3.0 is used and select the correct function and class
350 if (version_compare(WOOCOMMERCE_VERSION, '3.3.0', '>=')) {
351 echo '<div class="single_wc_actions">';
352 $this->admin_wc_actions($order, false);
353 } else {
354 echo '<div class="single_order_actions">';
355 $this->admin_order_actions($order, false);
356 }
357 echo '</div>';
358
359 $consignments = $this->get_order_shipments($order);
360 // show shipments if available
361 if ( ! empty($consignments)) {
362 ?>
363 <table class="tracktrace_status">
364 <thead>
365 <tr>
366 <th>&nbsp;</th>
367 <th><?php _e('Track & Trace', 'woocommerce-postnl'); ?></th>
368 <th><?php _e('Status', 'woocommerce-postnl'); ?></th>
369 </tr>
370 </thead>
371 <tbody>
372 <?php
373 $action = 'get_labels';
374 $target = (isset(WooCommerce_PostNL()->general_settings['download_display'])
375 && WooCommerce_PostNL()->general_settings['download_display'] == 'display')
376 ? 'target="_blank"'
377 : '';
378 $nonce = wp_create_nonce('wc_postnl');
379 $label_button_text = esc_attr__('Print PostNL label', 'woocommerce-postnl');
380 foreach ($consignments as $shipment_id => $shipment):
381 $shipment = WooCommerce_PostNL()->export->get_shipment_data($shipment_id, $order);
382 $label_url = wp_nonce_url(admin_url('admin-ajax.php?action=wc_postnl&request=get_labels&shipment_ids=' . $shipment_id),'wc_postnl');
383 if (isset($shipment['tracktrace'])) {
384 $tracktrace_url = $this->getTrackTraceUrl($order_id, $shipment['tracktrace']);
385 $tracktrace_link = sprintf('<a href="%s">%s</a>', $tracktrace_url, $shipment['tracktrace']);
386 } else {
387 if (isset($shipment['shipment']) && isset($shipment['shipment']['options'])) {
388 $tracktrace_link = '(' . WooCommerce_PostNL()->export->get_package_name( $shipment['shipment']['options']['package_type']) . ')';
389 } else {
390 $tracktrace_link = '(Unknown)';
391 }
392 }
393 $status = isset($shipment['status']) ? $shipment['status'] : '-';
394 ?>
395 <tr>
396 <td class="wcmp-create-label">
397 <?php
398 printf(
399 '<a href="%1$s" class="button tips postnl %2$s" alt="%3$s" data-tip="%3$s" data-order-id="%4$s" data-request="%2$s" data-nonce="%5$s" %6$s>',
400 $label_url,
401 $action,
402 $label_button_text,
403 $order_id,
404 $nonce,
405 $target
406 );
407 printf(
408 '<img class="wcmp_button_img" src="%1$s" alt="%2$s" width="16" />',
409 WooCommerce_PostNL()->plugin_url() . "/assets/img/postnl-pdf.png",
410 $label_button_text
411 );
412 printf("</a>");
413 ?>
414 </td>
415 <td class="wcmp-tracktrace"><?php echo $tracktrace_link; ?></td>
416 <td class="wcmp-status"><?php echo $status; ?></td>
417 </tr>
418 <?php endforeach ?>
419 </tbody>
420 </table>
421 <?php
422 }
423 }
424
425 public function single_order_shipment_options($order) {
426 $shipping_country = WCX_Order::get_prop($order, 'shipping_country');
427 if ( ! WooCommerce_PostNL()->export->is_postnl_destination($shipping_country)) {
428 return;
429 }
430
431 echo '<div style="clear:both;"><strong>' . __('PostNL shipment:', 'woocommerce-postnl') . '</strong><br/>';
432 $this->order_list_shipment_options($order, false);
433 echo '</div>';
434 }
435
436 public function show_order_delivery_options($order)
437 {
438 $delivery_options = WCX_Order::get_meta($order, '_postnl_delivery_options');
439 $shipping_country = WCX_Order::get_prop($order, 'shipping_country');
440
441 if ( ! empty($delivery_options) && is_array($delivery_options)) {
442 extract($delivery_options);
443 }
444
445 echo '<div class="delivery-options">';
446 if ( ! empty($date)
447 && ! (isset(WooCommerce_PostNL()->checkout_settings['deliverydays_window'])
448 && WooCommerce_PostNL()->checkout_settings['deliverydays_window'] == 0) &&
449 $shipping_country === 'NL'
450 ) {
451 $formatted_date = date_i18n(
452 apply_filters('wcpostnl_delivery_date_format', wc_date_format()),
453 strtotime($date)
454 );
455 if ( ! empty($time)) {
456 $time = array_shift($time); // take first element in time array
457 if (isset($time['price_comment'])) {
458 switch ($time['price_comment']) {
459 case 'morning':
460 $time_title = __('Morning delivery', 'woocommerce-postnl');
461 break;
462 case 'standard':
463 // $time_title = __( 'Standard delivery', 'woocommerce-postnl' );
464 break;
465 case 'evening':
466 case 'avond':
467 $time_title = __('Evening delivery', 'woocommerce-postnl');
468 break;
469 }
470 }
471 $time_title = ! empty($time_title) ? "({$time_title})" : '';
472 }
473
474 printf(
475 '<div class="delivery-date"><strong>%s: </strong>%s %s</div>',
476 __('Delivery date', 'woocommerce-postnl'),
477 $formatted_date,
478 $time_title
479 );
480 }
481
482 if ($pickup = WooCommerce_PostNL()->export->is_pickup($order, $delivery_options)) {
483 switch($pickup['price_comment']) {
484 case 'retail':
485 $title = __('PostNL Pickup', 'woocommerce-postnl');
486 break;
487 case 'retailexpress':
488 $title = __('PostNL Pickup Express', 'woocommerce-postnl');
489 break;
490 }
491
492 echo "<div class='pickup-location'><strong>{$title}: </strong>{$pickup['location']}, {$pickup['street']} {$pickup['number']}, {$pickup['postal_code']} {$pickup['city']}</div>";
493 }
494 echo '</div>';
495 }
496
497 public function getTrackTraceUrl($order_id, $tracktrace) {
498 if (empty($order_id)) {
499 return;
500 }
501
502 $order = WCX::get_order($order_id);
503 $country = WCX_Order::get_prop($order, 'shipping_country');
504 $postcode = preg_replace('/\s+/', '', WCX_Order::get_prop($order, 'shipping_postcode'));
505
506 // set url for NL or foreign orders
507 if ($country == 'NL') {
508 // use billing postcode for pickup/pakjegemak
509 if (WooCommerce_PostNL()->export->is_pickup($order)) {
510 $postcode = preg_replace('/\s+/', '', WCX_Order::get_prop($order, 'billing_postcode'));
511 }
512
513 $trackTraceUrlNl = sprintf(
514 'https://jouw.postnl.nl/#!/track-en-trace/%s/%s/%s',
515 $tracktrace,
516 $country,
517 $postcode
518 );
519
520 return $trackTraceUrlNl;
521 }
522
523 $trackTraceUrl = sprintf(
524 'https://www.internationalparceltracking.com/Main.aspx#/track/%s/%s/%s',
525 $tracktrace,
526 $country,
527 $postcode
528 );
529
530 return $trackTraceUrl;
531 }
532
533 public function get_tracktrace_links($order_id) {
534 if ($consignments = $this->get_tracktrace_shipments($order_id)) {
535 foreach ($consignments as $key => $consignment) {
536 $tracktrace_links[] = $consignment['tracktrace_link'];
537 }
538
539 return $tracktrace_links;
540 } else {
541 return false;
542 }
543 }
544
545 public function get_tracktrace_shipments($order_id) {
546 $order = WCX::get_order($order_id);
547 $shipments = $this->get_order_shipments($order, true);
548
549 if (empty($shipments)) {
550 return false;
551 }
552
553 foreach ($shipments as $shipment_id => $shipment) {
554 // skip concepts, letters & mailbox packages
555 if (empty($shipment['tracktrace'])) {
556 unset($shipments[$shipment_id]);
557 continue;
558 }
559 // add links & urls
560 $shipments[$shipment_id]['tracktrace_url'] = $tracktrace_url = $this->getTrackTraceUrl(
561 $order_id,
562 $shipment['tracktrace']
563 );
564 $shipments[$shipment_id]['tracktrace_link'] = sprintf(
565 '<a href="%s">%s</a>',
566 $tracktrace_url,
567 $shipment['tracktrace']
568 );
569 }
570
571 if (empty($shipments)) {
572 return false;
573 }
574
575 return $shipments;
576 }
577
578 public function product_hs_code_field() {
579 echo '<div class="options_group">';
580 woocommerce_wp_text_input(
581 array(
582 'id' => '_postnl_hs_code',
583 'label' => __('HS Code', 'woocommerce-postnl'),
584 'description' => sprintf(
585 __('HS Codes are used for PostNL world shipments, you can find the appropriate code on the %ssite of the Dutch Customs%s.', 'woocommerce-postnl'),
586 '<a href="http://tarief.douane.nl/arctictariff-public-web/#!/home" target="_blank">',
587 '</a>'
588 )
589 )
590 );
591 echo '</div>';
592 }
593
594 public function product_hs_code_field_save($post_id) {
595 // check if hs code is passed and not an array (=variation hs code)
596 if (isset($_POST['_postnl_hs_code']) && ! is_array($_POST['_postnl_hs_code'])) {
597 $product = wc_get_product($post_id);
598 $hs_code = $_POST['_postnl_hs_code'];
599 if ( ! empty($hs_code)) {
600 WCX_Product::update_meta_data($product, '_postnl_hs_code', esc_attr($hs_code));
601 } else {
602 if (isset($_POST['_postnl_hs_code']) && empty($hs_code)) {
603 WCX_Product::delete_meta_data($product, '_postnl_hs_code');
604 }
605 }
606 }
607 }
608
609 /**
610 * @snippet Add Column to Orders Table (e.g. Barcode) - WooCommerce
611 *
612 * @param $columns
613 *
614 * @return mixed
615 */
616 public function barcode_add_new_order_admin_list_column($columns)
617 {
618 // I want to display Barcode column just after the date column
619 return array_slice($columns, 0, 6, true)
620 + array('barcode' => 'Barcode')
621 + array_slice($columns, 6, null, true);
622 }
623
624 /**
625 * @param $column
626 */
627 public function barcode_add_new_order_admin_list_column_content($column)
628 {
629 global $post;
630 if ('barcode' === $column) {
631 $order = WCX::get_order($post->ID);
632 echo $this->get_barcode($order);
633 }
634 }
635 /**
636 * @param $order
637 * @param null $barcode
638 *
639 * @return string|null
640 */
641 public function get_barcode($order, $barcode = null)
642 {
643 $shipments = $this->get_order_shipments($order, true);
644 if (empty($shipments)) {
645 return __('No label has created yet', 'woocommerce-postnl');
646 }
647 foreach ($shipments as $shipment_id => $shipment) {
648 $barcode .= "<a target='_blank' href=" . $this->getTrackTraceUrl($order, $shipment['tracktrace']) . ">" . $shipment['tracktrace'] . "</a> <br>";
649 }
650 return $barcode;
651 }
652 }
653
654 endif; // class_exists
655
656 return new WooCommerce_PostNL_Admin();
657