Tax.php
1.07 KB
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
<?php
namespace ACA\WC\Column\Order;
use AC;
use ACA\WC\Sorting\Order\OrderData;
use ACP\ConditionalFormat\FilteredHtmlFormatTrait;
use ACP\ConditionalFormat\Formattable;
use ACP\Sorting\Sortable;
use ACP\Sorting\Type\DataType;
class Tax extends AC\Column implements Formattable, Sortable
{
use FilteredHtmlFormatTrait;
public function __construct()
{
$this->set_type('column-order_tax')
->set_label(__('Tax', 'codepress-admin-columns'))
->set_group('woocommerce');
}
public function get_value($id)
{
$order = wc_get_order($id);
$taxes = $order ? $order->get_tax_totals() : false;
if (empty($taxes)) {
return $this->get_empty_char();
}
$result = [];
foreach ($taxes as $tax) {
$result[] = sprintf('<small><strong>%s: </strong></small> %s', $tax->label, $tax->formatted_amount);
}
return implode('<br>', $result);
}
public function sorting()
{
return new OrderData('tax_amount', new DataType(DataType::NUMERIC));
}
}