From 2fd1a1088b052abc8d2170ebc99831dcf3bfd6ff Mon Sep 17 00:00:00 2001 From: Dima Uryvskiy Date: Mon, 23 Nov 2020 13:05:46 +0300 Subject: [PATCH] Fix client info if shipping address empty, use billing address --- .../abstracts/class-wc-retailcrm-abstracts-address.php | 7 ++++--- src/include/order/class-wc-retailcrm-order.php | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/include/abstracts/class-wc-retailcrm-abstracts-address.php b/src/include/abstracts/class-wc-retailcrm-abstracts-address.php index aae346e..a2a7b0f 100644 --- a/src/include/abstracts/class-wc-retailcrm-abstracts-address.php +++ b/src/include/abstracts/class-wc-retailcrm-abstracts-address.php @@ -91,12 +91,13 @@ abstract class WC_Retailcrm_Abstracts_Address extends WC_Retailcrm_Abstracts_Dat protected function getOrderAddress($order) { $orderAddress = $order->get_address($this->address_type); - - if (empty($orderAddress) && $this->address_type === self::ADDRESS_TYPE_BILLING && $this->fallback_to_shipping) { + $checkEmptyArray = array_filter($orderAddress); + + if (empty($checkEmptyArray) && $this->address_type === self::ADDRESS_TYPE_BILLING && $this->fallback_to_shipping) { $orderAddress = $order->get_address(self::ADDRESS_TYPE_SHIPPING); } - if (empty($orderAddress) && $this->address_type === self::ADDRESS_TYPE_SHIPPING && $this->fallback_to_billing) { + if (empty($checkEmptyArray) && $this->address_type === self::ADDRESS_TYPE_SHIPPING && $this->fallback_to_billing) { $orderAddress = $order->get_address(self::ADDRESS_TYPE_BILLING); } diff --git a/src/include/order/class-wc-retailcrm-order.php b/src/include/order/class-wc-retailcrm-order.php index a44ca6d..8eeb9e8 100644 --- a/src/include/order/class-wc-retailcrm-order.php +++ b/src/include/order/class-wc-retailcrm-order.php @@ -64,9 +64,9 @@ class WC_Retailcrm_Order extends WC_Retailcrm_Abstracts_Data $data = array( 'externalId' => $order->get_id(), - 'createdAt' => $order->get_date_created()->date('Y-m-d H:i:s'), - 'firstName' => $order->get_shipping_first_name(), - 'lastName' => $order->get_shipping_last_name(), + 'createdAt' => $order->get_date_created()->date('Y-m-d H:i:s'), + 'firstName' => $firstName, + 'lastName' => $lastName, 'email' => strtolower($order->get_billing_email()), 'customerComment' => $order->get_customer_note(), 'phone' => $order->get_billing_phone(),