@@ -28,6 +28,16 @@ class Shipping {
28
28
*/
29
29
private $ address ;
30
30
31
+ /**
32
+ * Custom contact email address, usually added via the Contact Module.
33
+ */
34
+ private ?string $ email_address = null ;
35
+
36
+ /**
37
+ * Custom contact phone number, usually added via the Contact Module.
38
+ */
39
+ private ?Phone $ phone_number = null ;
40
+
31
41
/**
32
42
* Shipping methods.
33
43
*
@@ -38,14 +48,18 @@ class Shipping {
38
48
/**
39
49
* Shipping constructor.
40
50
*
41
- * @param string $name The name.
42
- * @param Address $address The address.
43
- * @param ShippingOption[] $options Shipping methods.
51
+ * @param string $name The name.
52
+ * @param Address $address The address.
53
+ * @param string|null $email_address Contact email.
54
+ * @param Phone|null $phone_number Contact phone.
55
+ * @param ShippingOption[] $options Shipping methods.
44
56
*/
45
- public function __construct ( string $ name , Address $ address , array $ options = array () ) {
46
- $ this ->name = $ name ;
47
- $ this ->address = $ address ;
48
- $ this ->options = $ options ;
57
+ public function __construct ( string $ name , Address $ address , string $ email_address = null , Phone $ phone_number = null , array $ options = array () ) {
58
+ $ this ->name = $ name ;
59
+ $ this ->address = $ address ;
60
+ $ this ->email_address = $ email_address ;
61
+ $ this ->phone_number = $ phone_number ;
62
+ $ this ->options = $ options ;
49
63
}
50
64
51
65
/**
@@ -66,6 +80,24 @@ public function address(): Address {
66
80
return $ this ->address ;
67
81
}
68
82
83
+ /**
84
+ * Returns the contact email address, or null.
85
+ *
86
+ * @return null|string
87
+ */
88
+ public function email_address () : ?string {
89
+ return $ this ->email_address ;
90
+ }
91
+
92
+ /**
93
+ * Returns the contact phone number, or null.
94
+ *
95
+ * @return null|Phone
96
+ */
97
+ public function phone_number () : ?Phone {
98
+ return $ this ->phone_number ;
99
+ }
100
+
69
101
/**
70
102
* Returns the shipping methods.
71
103
*
@@ -87,6 +119,17 @@ public function to_array(): array {
87
119
),
88
120
'address ' => $ this ->address ()->to_array (),
89
121
);
122
+
123
+ $ contact_email = $ this ->email_address ();
124
+ $ contact_phone = $ this ->phone_number ();
125
+
126
+ if ( $ contact_email ) {
127
+ $ result ['email_address ' ] = $ contact_email ;
128
+ }
129
+ if ( $ contact_phone ) {
130
+ $ result ['phone_number ' ] = $ contact_phone ->to_array ();
131
+ }
132
+
90
133
if ( $ this ->options ) {
91
134
$ result ['options ' ] = array_map (
92
135
function ( ShippingOption $ opt ): array {
0 commit comments