6
6
7
7
class Coopcycle_Extend_Woo_Core
8
8
{
9
-
10
9
/**
11
10
* Plugin Identifier, unique to each plugin.
12
11
*
@@ -21,8 +20,8 @@ public function init()
21
20
{
22
21
$ this ->save_shipping_date ();
23
22
$ this ->show_shipping_date_in_order ();
24
- // $this->show_shipping_instructions_in_order_confirmation ();
25
- // $this->show_shipping_instructions_in_order_email ();
23
+ $ this ->show_shipping_date_in_order_confirmation ();
24
+ $ this ->show_shipping_date_in_order_email ();
26
25
}
27
26
28
27
/**
@@ -75,71 +74,51 @@ function (\WC_Order $order) {
75
74
/**
76
75
* Adds the pickup date and time on the order confirmation page.
77
76
*/
78
- private function show_shipping_instructions_in_order_confirmation ()
77
+ private function show_shipping_date_in_order_confirmation ()
79
78
{
80
79
add_action (
81
- 'woocommerce_thankyou ' ,
82
- function (int $ order_id ) {
83
- $ order = wc_get_order ($ order_id );
84
- $ shipping_methods = $ order ->get_shipping_methods ();
85
- $ shipping_method = reset ( $ shipping_methods );
80
+ 'woocommerce_order_details_after_customer_address ' ,
81
+ function ($ type , $ order ) {
82
+ if ($ type === 'shipping ' ) {
83
+ if ($ order ->meta_exists ('shipping_date ' )) {
86
84
87
- if ($ shipping_method ?->get_method_id() === 'pickup_location ' ) {
88
- $ pickup_date = $ order ->get_meta ('your-extension-name_pickup_date ' );
85
+ $ shipping_date = $ order ->get_meta ('shipping_date ' );
89
86
90
- if ('' !== $ pickup_date ) {
91
87
printf (
92
- "<h2>%s</h2>
93
- <p>%s %s</p>
94
- <p><strong>%s</strong><br>%s</p>
95
- <p><strong>%s</strong><br>%s</p> " ,
96
- esc_html__ ('Order pickup ' , $ this ->name ),
97
- esc_html__ ('You chose ' , $ this ->name ),
98
- $ order ->get_shipping_method (),
99
- esc_html__ ('Pickup location ' , $ this ->name ),
100
- $ shipping_method ->get_meta ('pickup_address ' ),
101
- esc_html__ ('Pickup date and time ' , $ this ->name ),
102
- esc_html (wp_date ('j F Y at H:i ' , strtotime ($ pickup_date ))),
88
+ "<strong>%s</strong>
89
+ <span>%s</span> " ,
90
+ esc_html__ ('Shipping date ' , $ this ->name ),
91
+ esc_html ($ shipping_date )
103
92
);
104
93
}
105
94
}
106
95
},
107
- priority: 9 , accepted_args: 1
96
+ priority: 9 ,
97
+ accepted_args: 2
108
98
);
109
99
}
110
100
111
101
/**
112
- * Adds the pickup date and time on the order confirmation email.
102
+ * Adds the shipping date and time on the order confirmation email.
113
103
*/
114
- private function show_shipping_instructions_in_order_email ()
104
+ private function show_shipping_date_in_order_email ()
115
105
{
116
106
add_action (
117
107
'woocommerce_email_after_order_table ' ,
118
108
function ($ order , $ sent_to_admin , $ plain_text , $ email ) {
119
- $ shipping_methods = $ order ->get_shipping_methods ();
120
- $ shipping_method = reset ( $ shipping_methods );
121
-
122
- if ($ shipping_method ?->get_method_id() === 'pickup_location ' ) {
123
- $ pickup_date = $ order ->get_meta ('your-extension-name_pickup_date ' );
109
+ if ($ order ->meta_exists ('shipping_date ' )) {
110
+ $ shipping_date = $ order ->get_meta ('shipping_date ' );
124
111
125
- if ('' !== $ pickup_date ) {
126
- printf (
127
- "<h2>%s</h2>
128
- <p>%s %s</p>
129
- <p><strong>%s</strong><br>%s</p>
130
- <p><strong>%s</strong><br>%s</p> " ,
131
- esc_html__ ('Order pickup ' , $ this ->name ),
132
- esc_html__ ('You chose ' , $ this ->name ),
133
- $ order ->get_shipping_method (),
134
- esc_html__ ('Pickup location ' , $ this ->name ),
135
- $ shipping_method ->get_meta ('pickup_address ' ),
136
- esc_html__ ('Pickup date and time ' , $ this ->name ),
137
- esc_html (wp_date ('j F Y at H:i ' , strtotime ($ pickup_date ))),
138
- );
139
- }
112
+ printf (
113
+ "<h2>%s</h2>
114
+ <p>%s</p> " ,
115
+ esc_html__ ('Shipping date ' , $ this ->name ),
116
+ esc_html ($ shipping_date )
117
+ );
140
118
}
141
119
},
142
- priority: 10 , accepted_args: 4
120
+ priority: 10 ,
121
+ accepted_args: 4
143
122
);
144
123
}
145
124
}
0 commit comments