diff --git a/src/include/class-wc-retailcrm-loyalty.php b/src/include/class-wc-retailcrm-loyalty.php index ca4ee50..c065e6a 100644 --- a/src/include/class-wc-retailcrm-loyalty.php +++ b/src/include/class-wc-retailcrm-loyalty.php @@ -44,6 +44,13 @@ if (!class_exists('WC_Retailcrm_Loyalty')) : public function getForm(int $userId) { $result = []; + $phone = ''; + + $wcCustomer = new WC_Customer($userId); + + if ($wcCustomer instanceof WC_Customer) { + $phone = $wcCustomer->get_billing_phone(); + } try { $response = $this->getLoyaltyAccounts($userId); @@ -68,7 +75,7 @@ if (!class_exists('WC_Retailcrm_Loyalty')) : $result['loyaltyId'] = $loyaltyAccount['id']; } } else { - $result['form'] = $this->loyaltyForm->getRegistrationForm(); + $result['form'] = $this->loyaltyForm->getRegistrationForm($phone); } return $result; @@ -84,6 +91,17 @@ if (!class_exists('WC_Retailcrm_Loyalty')) : ]; try { + $wcCustomer = new WC_Customer($userId); + + if ($wcCustomer instanceof WC_Customer) { + $currentPhone = $wcCustomer->get_billing_phone(); + + if (empty($currentPhone) && $phone !== '') { + $wcCustomer->set_billing_phone($phone); + $wcCustomer->save(); + } + } + $response = $this->apiClient->createLoyaltyAccount($parameters, $site); if (!$response->isSuccessful()) { diff --git a/src/include/components/class-wc-retailcrm-loyalty-form.php b/src/include/components/class-wc-retailcrm-loyalty-form.php index 0e600db..c398b8c 100644 --- a/src/include/components/class-wc-retailcrm-loyalty-form.php +++ b/src/include/components/class-wc-retailcrm-loyalty-form.php @@ -5,7 +5,7 @@ if (!class_exists('WC_Retailcrm_Loyalty')) : class WC_Retailcrm_Loyalty_Form { - public function getRegistrationForm() + public function getRegistrationForm($phone = '') { return sprintf( ' @@ -13,7 +13,7 @@ if (!class_exists('WC_Retailcrm_Loyalty')) :
%s
%s%s.
%s%s.
- +