-
Notifications
You must be signed in to change notification settings - Fork 0
/
DownloadLabelBox.php
61 lines (50 loc) · 2.19 KB
/
DownloadLabelBox.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace DpdConnect\classes\Handlers;
use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
use DpdConnect\classes\Database\Label;
use DpdConnect\classes\enums\ParcelType;
class DownloadLabelBox
{
public static function handle()
{
add_filter('add_meta_boxes', [self::class, 'add']);
}
public static function add()
{
$screen = wc_get_container()->get( CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled()
? wc_get_page_screen_id( 'shop-order' )
: 'shop_order';
add_meta_box('dpdconnect_pdf', __('DPD Connect Download Labels', 'dpdconnect'), [self::class, 'render'], $screen, 'side', 'high');
}
/**
* @param \WC_Order $order
* @return void
*/
public static function render($order)
{
$labelRepo = new Label();
$shippingLabels = $labelRepo->getByOrderId($order->get_id(), ParcelType::TYPEREGULAR, true);
$returnLabels = $labelRepo->getByOrderId($order->get_id(), ParcelType::TYPERETURN, true);
echo '<table>';
if (!$shippingLabels && !$returnLabels) {
echo '<tr><td>' . __('No labels available.') . '</a></td></tr>';
}
if ($shippingLabels) {
foreach ($shippingLabels as $shippingLabel) {
$shippingId = $shippingLabel['id'];
$shippingUrl = add_query_arg(['plugin' => 'dpdconnect', 'file' => 'shipping_label', 'id' => $shippingId], admin_url());
echo '<tr><td><a href="' . $shippingUrl . '">' . __('Shipping label', 'dpdconnect') . '</a></td>';
echo '<td>' . $shippingLabel['created_at'] . '</td></tr>';
}
}
if ($returnLabels) {
foreach ($returnLabels as $returnLabel) {
$returnId = $returnLabel['id'];
$returnUrl = add_query_arg(['plugin' => 'dpdconnect', 'file' => 'shipping_label', 'id' => $returnId], admin_url());
echo '<tr><td><a href="' . $returnUrl . '">' . __('Return label', 'dpdconnect') . '</a></td>';
echo '<td>' . $returnLabel['created_at'] . '</td></tr>';
}
}
echo '</table>';
}
}