diff --git a/admin/customers.php b/admin/customers.php index 1b8f3a9..10e1745 100644 --- a/admin/customers.php +++ b/admin/customers.php @@ -34,6 +34,26 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { } else { $stmt = $pdo->prepare("INSERT INTO customers (name, email, phone, address) VALUES (?, ?, ?, ?)"); $stmt->execute([$name, $email, $phone, $address]); + + // --- Send Welcome WhatsApp Message via Wablas --- + if (!empty($phone)) { + try { + require_once __DIR__ . '/../includes/WablasService.php'; + $wablas = new WablasService($pdo); + $companyStmt = $pdo->query("SELECT company_name FROM company_settings LIMIT 1"); + $companyName = $companyStmt->fetchColumn() ?: 'Our Restaurant'; + + $settingsStmt = $pdo->query("SELECT points_for_free_meal FROM loyalty_settings WHERE id = 1"); + $settings = $settingsStmt->fetch(PDO::FETCH_ASSOC); + $threshold = $settings ? intval($settings['points_for_free_meal']) : 70; + + $welcomeMsg = "Welcome *{$name}* to *{$companyName}*! 🎉\n\nThank you for registering. You can now earn loyalty points with every order!\n\nYou currently have 0 points. Collect {$threshold} points to earn a free meal!"; + $wablas->sendMessage($phone, $welcomeMsg); + } catch (Exception $w) { + error_log("Wablas Admin Welcome Exception: " . $w->getMessage()); + } + } + $message = '
Customer created successfully!
'; } } @@ -89,11 +109,13 @@ include 'includes/header.php';

Customer Relationship

Manage your customer database and contact info

- + - + @@ -114,13 +136,15 @@ include 'includes/header.php'; - +

No customers found

No results matching your search criteria.

- +
@@ -134,7 +158,8 @@ include 'includes/header.php'; - + - +
@@ -152,23 +177,28 @@ include 'includes/header.php';
- pts + pts
- + - + - + Delete - +
@@ -176,10 +206,12 @@ include 'includes/header.php';
- + - +