| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* The shipment summary that shows when you click (i) in an order. |
| 5 |
*/ |
| 6 |
|
| 7 |
use MyParcelNL\Sdk\src\Support\Arr; |
| 8 |
use WPO\WC\PostNL\Compatibility\WC_Core as WCX; |
| 9 |
|
| 10 |
if (! defined('ABSPATH')) { |
| 11 |
exit; |
| 12 |
} // Exit if accessed directly |
| 13 |
|
| 14 |
$order_id = $_POST["order_id"]; |
| 15 |
$shipment_id = $_POST["shipment_id"]; |
| 16 |
|
| 17 |
$order = WCX::get_order($order_id); |
| 18 |
|
| 19 |
$shipments = WCPOST()->export->getShipmentData([$shipment_id], $order); |
| 20 |
$deliveryOptions = WCPOST_Admin::getDeliveryOptionsFromOrder($order); |
| 21 |
|
| 22 |
$option_strings = [ |
| 23 |
"signature" => __("Signature on delivery", "woocommerce-postnl"), |
| 24 |
"only_recipient" => __("Only recipient", "woocommerce-postnl"), |
| 25 |
]; |
| 26 |
|
| 27 |
$firstShipment = $shipments[$shipment_id]; |
| 28 |
|
| 29 |
/** |
| 30 |
* Show options only for the first shipment as they are all the same. |
| 31 |
*/ |
| 32 |
$insurance = Arr::get($firstShipment, "shipment.options.insurance"); |
| 33 |
$labelDescription = Arr::get($firstShipment, "shipment.options.label_description"); |
| 34 |
|
| 35 |
echo '<ul class="wcpn__shipment-summary">'; |
| 36 |
|
| 37 |
/** |
| 38 |
* Package type |
| 39 |
*/ |
| 40 |
printf( |
| 41 |
'%s: %s', |
| 42 |
__("Shipment type", "woocommerce-postnl"), |
| 43 |
WCPN_Data::getPackageTypeHuman(Arr::get($firstShipment, "shipment.options.package_type")) |
| 44 |
); |
| 45 |
|
| 46 |
foreach ($option_strings as $key => $label) { |
| 47 |
if (Arr::get($firstShipment, "shipment.options.$key") |
| 48 |
&& (int) Arr::get($firstShipment, "shipment.options.$key") === 1) { |
| 49 |
printf('<li class="%s">%s</li>', $key, $label); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
if ($insurance) { |
| 54 |
$price = number_format(Arr::get($insurance, "amount") / 100, 2); |
| 55 |
printf('<li>%s: € %s</li>', __("Insured for", "woocommerce-postnl"), $price); |
| 56 |
} |
| 57 |
|
| 58 |
if ($labelDescription) { |
| 59 |
printf( |
| 60 |
'<li>%s: %s</li>', |
| 61 |
__("Label description", "woocommerce-postnl"), |
| 62 |
$labelDescription |
| 63 |
); |
| 64 |
} |
| 65 |
echo '</ul>'; |
| 66 |
|
| 67 |
echo "<hr>"; |
| 68 |
|
| 69 |
/** |
| 70 |
* Do show the Track & Trace status for all shipments. |
| 71 |
*/ |
| 72 |
foreach ($shipments as $shipment_id => $shipment) { |
| 73 |
$trackTrace = Arr::get($shipment, "track_trace"); |
| 74 |
|
| 75 |
/** |
| 76 |
* Show Track & Trace status. |
| 77 |
*/ |
| 78 |
if (! $trackTrace) { |
| 79 |
continue; |
| 80 |
} |
| 81 |
|
| 82 |
printf( |
| 83 |
'<a href="%2$s" target="_blank" title="%3$s">%3$s</a><br/> %1$s: %4$s<br/>', |
| 84 |
__("Status", "woocommerce-postnl"), |
| 85 |
WCPOST_Admin::getTrackTraceUrl($order_id, $trackTrace), |
| 86 |
$trackTrace, |
| 87 |
Arr::get($shipment, "status") |
| 88 |
); |
| 89 |
} |
| 90 |
|