ShippingAddress.php
3.43 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
namespace ACA\WC\Column\Order\Address;
use AC;
use ACA\WC\Editing;
use ACA\WC\Search;
use ACA\WC\Settings;
use ACA\WC\Sorting;
use ACA\WC\Type\AddressType;
use ACP;
class ShippingAddress extends AC\Column implements ACP\Search\Searchable, ACP\Editing\Editable, ACP\Export\Exportable,
ACP\ConditionalFormat\Formattable, ACP\Sorting\Sortable
{
use ACP\ConditionalFormat\ConditionalFormatTrait;
public function __construct()
{
$this->set_type('column-order_shipping_address')
->set_label(__('Shipping Address', 'codepress-admin-columns'))
->set_group('woocommerce');
}
public function sorting()
{
$display_property = $this->get_display_property();
switch ($display_property) {
case 'address_1':
case 'address_2':
case 'city':
case 'company':
case 'country':
case 'first_name':
case 'last_name':
case 'postcode':
case 'phone':
case 'state':
return new Sorting\Order\AddressField($display_property, $this->get_address_type());
case 'full_name':
return new Sorting\Order\FullNameAddress($this->get_address_type());
default:
return false;
}
}
public function get_value($id)
{
$order = wc_get_order($id);
$method = $this->get_address_map($this->get_display_property());
$value = method_exists($order, $method)
? $order->$method()
: false;
return $value ?: $this->get_empty_char();
}
private function get_display_property(): string
{
$setting = $this->get_setting('address_property');
return $setting instanceof Settings\Address
? $setting->get_address_property()
: '';
}
private function get_address_map(string $property): string
{
$mapping = [
'address_1' => 'get_shipping_address_1',
'address_2' => 'get_shipping_address_2',
'city' => 'get_shipping_city',
'company' => 'get_shipping_company',
'country' => 'get_shipping_country',
'first_name' => 'get_shipping_first_name',
'last_name' => 'get_shipping_last_name',
'full_name' => 'get_formatted_shipping_full_name',
'postcode' => 'get_shipping_postcode',
'state' => 'get_shipping_state',
'email' => 'get_shipping_email',
'phone' => 'get_shipping_phone',
];
return $mapping[$property] ?? 'get_formatted_billing_address';
}
protected function register_settings()
{
parent::register_settings();
$this->add_setting(new Settings\Address($this));
}
private function get_address_type(): AddressType
{
return new AddressType(AddressType::SHIPPING);
}
public function search()
{
return (new Search\Order\AddressesComparisonFactory($this->get_address_type()))->create(
$this->get_display_property()
);
}
public function editing()
{
$factory = new Editing\Order\AddressServiceFactory($this->get_address_type());
return $factory->create($this->get_display_property());
}
public function export()
{
return new ACP\Export\Model\StrippedValue($this);
}
}