← All changes
|
includes/controllers/WooMailerLiteOrderController.php
+16
-12
3.1.25
→
3.1.27
View file →
| @@ -14,9 +14,9 @@ | ||
| 14 | 14 | if (!$order->get_billing_email()) { |
| 15 | 15 | return true; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | - $this->persistLanguageToOrder($order); | |
| 18 | + WooMailerLiteLanguageService::persistToOrder($order); | |
| 19 | 19 | |
| 20 | 20 | if (WooMailerLiteSession::getMLCartHash()) { |
| 21 | 21 | $order->add_meta_data('_woo_ml_cart_hash', WooMailerLiteSession::getMLCartHash()); |
| 22 | 22 | } |
| @@ -81,12 +81,19 @@ | ||
| 81 | 81 | $syncFields[] = 'name'; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | $customerFields = array_intersect_key($filteredCustomerData, array_flip($syncFields)); |
| 85 | - if (WooMailerLiteOptions::get('settings.languageField')) { | |
| 86 | - $customerFields['subscriber_language'] = $order->get_meta('_woo_ml_language'); | |
| 85 | + | |
| 86 | + if (in_array('phone', $syncFields) && empty($customerFields['phone']) && $order->get_billing_phone()) { | |
| 87 | + $customerFields['phone'] = $order->get_billing_phone(); | |
| 87 | 88 | } |
| 88 | 89 | |
| 90 | + if (in_array('company', $syncFields) && empty($customerFields['company']) && $order->get_billing_company()) { | |
| 91 | + $customerFields['company'] = $order->get_billing_company(); | |
| 92 | + } | |
| 93 | + | |
| 94 | + $customerFields = WooMailerLiteLanguageService::applyTo($customerFields, $order); | |
| 95 | + | |
| 89 | 96 | $subscribe = false; |
| 90 | 97 | $email = $customer->email ?? $order->get_billing_email(); |
| 91 | 98 | $subscribeCacheKey = 'woo_ml_subscribe_checkbox:'.$email; |
| 92 | 99 | if ($cart && isset($cart->subscribe)) { |
| @@ -242,16 +249,13 @@ | ||
| 242 | 249 | return true; |
| 243 | 250 | } |
| 244 | 251 | } |
| 245 | 252 | |
| 246 | - private function persistLanguageToOrder($order): void | |
| 253 | + /** | |
| 254 | + * Snapshots the language while the order is being created, so gateway | |
| 255 | + * callbacks and later status changes do not need the shopper's session. | |
| 256 | + */ | |
| 257 | + public function persistLanguageForOrder($order): void | |
| 247 | 258 | { |
| 248 | - $key = '_woo_ml_language'; | |
| 249 | - if (isset(WC()->session)) { | |
| 250 | - $language = WC()->session->get($key); | |
| 251 | - if ($language && !$order->get_meta($key)) { | |
| 252 | - $order->add_meta_data($key, $language); | |
| 253 | - $order->save(); | |
| 254 | - } | |
| 255 | - } | |
| 259 | + WooMailerLiteLanguageService::persistToOrder($order); | |
| 256 | 260 | } |
| 257 | 261 | } |