1
0
Fork 0
mirror of synced 2025-04-02 21:36:14 +03:00

Added automatic substitution of phone number into the loyalty program registration form.

Added saving of phone number when registering in the loyalty program
This commit is contained in:
Ivan Chaplygin 2024-09-30 12:16:47 +03:00
parent b00ff321ab
commit 8e5cb10d57
2 changed files with 22 additions and 3 deletions

View file

@ -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()) {

View file

@ -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')) :
<p>%s</p>
<p><input type="checkbox" name="terms" id="termsLoyalty" required>%s<a id="terms-popup" class="popup-open-loyalty" href="#">%s</a>.</p>
<p><input type="checkbox" name="privacy" id="privacyLoyalty" required>%s<a id="privacy-popup" class="popup-open-loyalty" href="#">%s</a>.</p>
<p><input type="text" name="phone" id="phoneLoyalty" placeholder="%s" required></p>
<p><input type="text" name="phone" id="phoneLoyalty" placeholder="%s" value="%s" required></p>
<p><input type="submit" value="%s"></p>
</form>
<div class="popup-fade-loyalty">
@ -30,6 +30,7 @@ if (!class_exists('WC_Retailcrm_Loyalty')) :
__(' I agree with ', 'retailcrm'),
__('terms of personal data processing', 'retailcrm'),
__('Phone', 'retailcrm'),
$phone,
__('Send', 'retailcrm'),
__('Close', 'retailcrm')
);