diff --git a/src/include/class-wc-retailcrm-orders.php b/src/include/class-wc-retailcrm-orders.php index 0f15610..fb11e8c 100644 --- a/src/include/class-wc-retailcrm-orders.php +++ b/src/include/class-wc-retailcrm-orders.php @@ -189,8 +189,17 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : } if ($update && $customerWasChanged) { - $this->order['firstName'] = $wcOrder->get_shipping_first_name(); - $this->order['lastName'] = $wcOrder->get_shipping_last_name(); + $firstName = $wcOrder->get_shipping_first_name(); + $lastName = $wcOrder->get_shipping_last_name(); + + if(empty($firstName) && empty($lastName)) + { + $firstName = $wcOrder->get_billing_first_name(); + $lastName = $wcOrder->get_billing_last_name(); + } + + $this->order['firstName'] = $firstName; + $this->order['lastName'] = $lastName; } return true; diff --git a/src/include/order/class-wc-retailcrm-order.php b/src/include/order/class-wc-retailcrm-order.php index 2f82450..2c9e083 100644 --- a/src/include/order/class-wc-retailcrm-order.php +++ b/src/include/order/class-wc-retailcrm-order.php @@ -53,11 +53,20 @@ class WC_Retailcrm_Order extends WC_Retailcrm_Abstracts_Data */ public function build($order) { + $firstName = $order->get_shipping_first_name(); + $lastName = $order->get_shipping_last_name(); + + if(empty($firstName) && empty($lastName)) + { + $firstName = $order->get_billing_first_name(); + $lastName = $order->get_billing_last_name(); + } + $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(), + 'firstName' => $firstName, + 'lastName' => $lastName, 'email' => $order->get_billing_email(), 'customerComment' => $order->get_customer_note(), 'phone' => $order->get_billing_phone(),