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 = '
No customers found
No results matching your search criteria.
-
+
@@ -241,6 +273,7 @@ function prepareEditForm(customer) {
document.getElementById('customerAddress').value = customer.address || '';
}
-
+
-
+
\ No newline at end of file
diff --git a/admin/integrations.php b/admin/integrations.php
index 7d2728a..3dbada2 100644
--- a/admin/integrations.php
+++ b/admin/integrations.php
@@ -38,7 +38,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Wablas
if ($provider === 'wablas') {
- $keys = ['domain', 'token', 'secret_key', 'order_template', 'is_enabled'];
+ $keys = ['domain', 'token', 'secret_key', 'order_template', 'welcome_template', 'is_enabled'];
foreach ($keys as $k) {
$val = $_POST[$k] ?? '0';
if ($k === 'is_enabled' && !isset($_POST[$k])) {
@@ -110,6 +110,7 @@ $wablasDom = getSetting($allSettings, 'wablas', 'domain');
$wablasTok = getSetting($allSettings, 'wablas', 'token');
$wablasSecKey = getSetting($allSettings, 'wablas', 'secret_key');
$wablasTemplate = getSetting($allSettings, 'wablas', 'order_template');
+$wablasWelcomeTemplate = getSetting($allSettings, 'wablas', 'welcome_template');
$wablasEnabled = getSetting($allSettings, 'wablas', 'is_enabled');
// SMTP Settings
@@ -136,6 +137,14 @@ You've earned *{points_earned} points* with this order.
💰 *Current Balance: {new_balance} points*";
}
+if (empty($wablasWelcomeTemplate)) {
+ $wablasWelcomeTemplate = "Welcome *{customer_name}* to *{company_name}*! 🎉
+
+Thank you for registering. You can now earn loyalty points with every order!
+
+You currently have 0 points. Collect {points_threshold} points to earn a free meal!";
+}
+
require_once __DIR__ . '/includes/header.php';
?>
@@ -302,6 +311,15 @@ require_once __DIR__ . '/includes/header.php';
+
+
+
+
+ Available Variables:
+ {customer_name}, {company_name}, {points_threshold}.
+
+
+
diff --git a/api/create_customer.php b/api/create_customer.php
index 3027178..7ecd43d 100644
--- a/api/create_customer.php
+++ b/api/create_customer.php
@@ -44,6 +44,34 @@ try {
$settings = $settingsStmt->fetch(PDO::FETCH_ASSOC);
$threshold = $settings ? intval($settings['points_for_free_meal']) : 70;
+ // --- Send Welcome WhatsApp Message via Wablas ---
+ 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';
+
+ // Fetch welcome template
+ $templateStmt = $pdo->query("SELECT setting_value FROM integration_settings WHERE provider='wablas' AND setting_key='welcome_template'");
+ $welcomeTemplate = $templateStmt->fetchColumn();
+
+ if (empty($welcomeTemplate)) {
+ $welcomeTemplate = "Welcome *{customer_name}* to *{company_name}*! 🎉\n\nThank you for registering. You can now earn loyalty points with every order!\n\nYou currently have 0 points. Collect {points_threshold} points to earn a free meal!";
+ }
+
+ $welcomeMsg = str_replace(
+ ['{customer_name}', '{company_name}', '{points_threshold}'],
+ [$name, $companyName, $threshold],
+ $welcomeTemplate
+ );
+
+
+ $wablas->sendMessage($phone, $welcomeMsg);
+ } catch (Exception $w) {
+ error_log("Wablas Welcome Msg Exception: " . $w->getMessage());
+ }
+
echo json_encode([
'success' => true,
'customer' => [
@@ -62,4 +90,4 @@ try {
} catch (Exception $e) {
error_log("Create Customer Error: " . $e->getMessage());
echo json_encode(['error' => 'Database error']);
-}
\ No newline at end of file
+}
diff --git a/api/order.php b/api/order.php
index 502ea71..e57474a 100644
--- a/api/order.php
+++ b/api/order.php
@@ -359,8 +359,8 @@ try {
$pdo->commit();
// --- Post-Transaction Actions (WhatsApp) ---
- // DISABLED TEMPORARILY AS PER USER REQUEST
- /*
+
+
if ($customer_id && $customer_phone) {
try {
$final_points = $current_points - $points_deducted + ($loyalty_enabled ? $points_awarded : 0);
@@ -423,7 +423,7 @@ You've earned *{points_earned} points* with this order.
error_log("Wablas Exception: " . $w->getMessage());
}
}
- */
+
echo json_encode(['success' => true, 'order_id' => $order_id]);
diff --git a/cookies.txt b/cookies.txt
index b87e7bd..9f13eb5 100644
--- a/cookies.txt
+++ b/cookies.txt
@@ -2,4 +2,4 @@
# https://curl.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
-#HttpOnly_127.0.0.1 FALSE / FALSE 1772904726 PHPSESSID p7okqi6joq82i0rfhlmbbj2pgd
+#HttpOnly_127.0.0.1 FALSE / FALSE 1773424134 PHPSESSID p5u70l3ue978cjhaqb88q2fob2