From d7b132d9d9c9708e974ef7102ce2e8ada994eab6 Mon Sep 17 00:00:00 2001 From: Dwindi Ramadhana Date: Wed, 7 Jan 2026 22:40:45 +0700 Subject: [PATCH] fix: dbDelta separate tables, add SEOHead for page titles 1. License table creation: - dbDelta requires separate calls per CREATE TABLE - Split into sql_licenses and sql_activations - Added 'PRIMARY KEY (id)' with two spaces (dbDelta requirement) 2. Page titles: - Added SEOHead to Cart page (title: Shopping Cart) - Added SEOHead to Checkout page (title: Checkout) - Shop already had SEOHead 3. usePageTitle hook created (alternative to SEOHead for non-Helmet usage) --- customer-spa/src/hooks/usePageTitle.ts | 22 +++++++++++++++++++ customer-spa/src/pages/Cart/index.tsx | 2 ++ customer-spa/src/pages/Checkout/index.tsx | 2 ++ includes/Modules/Licensing/LicenseManager.php | 19 ++++++++++------ 4 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 customer-spa/src/hooks/usePageTitle.ts diff --git a/customer-spa/src/hooks/usePageTitle.ts b/customer-spa/src/hooks/usePageTitle.ts new file mode 100644 index 0000000..ba56438 --- /dev/null +++ b/customer-spa/src/hooks/usePageTitle.ts @@ -0,0 +1,22 @@ +import { useEffect } from 'react'; + +/** + * Hook to set the document title dynamically + * @param title - The page title to set + * @param suffix - Optional suffix (default: store name from settings) + */ +export function usePageTitle(title: string, suffix?: string) { + useEffect(() => { + const storeName = (window as any).woonoowCustomer?.storeName || 'Store'; + const finalSuffix = suffix ?? storeName; + + document.title = title ? `${title} | ${finalSuffix}` : finalSuffix; + + // Cleanup: restore original title when component unmounts + return () => { + // Don't restore - let the next page set its own title + }; + }, [title, suffix]); +} + +export default usePageTitle; diff --git a/customer-spa/src/pages/Cart/index.tsx b/customer-spa/src/pages/Cart/index.tsx index 47052a4..8fa65a3 100644 --- a/customer-spa/src/pages/Cart/index.tsx +++ b/customer-spa/src/pages/Cart/index.tsx @@ -13,6 +13,7 @@ import { DialogTitle, } from '@/components/ui/dialog'; import Container from '@/components/Layout/Container'; +import SEOHead from '@/components/SEOHead'; import { formatPrice } from '@/lib/currency'; import { Trash2, Plus, Minus, ShoppingBag, ArrowLeft, Loader2, X, Tag } from 'lucide-react'; import { toast } from 'sonner'; @@ -155,6 +156,7 @@ export default function Cart() { return ( +
{/* Header */}
diff --git a/customer-spa/src/pages/Checkout/index.tsx b/customer-spa/src/pages/Checkout/index.tsx index 5502d9c..b278042 100644 --- a/customer-spa/src/pages/Checkout/index.tsx +++ b/customer-spa/src/pages/Checkout/index.tsx @@ -4,6 +4,7 @@ import { useCartStore } from '@/lib/cart/store'; import { useCheckoutSettings } from '@/hooks/useAppearanceSettings'; import { Button } from '@/components/ui/button'; import Container from '@/components/Layout/Container'; +import SEOHead from '@/components/SEOHead'; import { formatPrice } from '@/lib/currency'; import { ArrowLeft, ShoppingBag, MapPin, Check, Edit2, Loader2, X, Tag } from 'lucide-react'; import { toast } from 'sonner'; @@ -339,6 +340,7 @@ export default function Checkout() { return ( +
{/* Header */}
diff --git a/includes/Modules/Licensing/LicenseManager.php b/includes/Modules/Licensing/LicenseManager.php index cb9d238..077597f 100644 --- a/includes/Modules/Licensing/LicenseManager.php +++ b/includes/Modules/Licensing/LicenseManager.php @@ -42,7 +42,10 @@ class LicenseManager { $licenses_table = $wpdb->prefix . self::$table_name; $activations_table = $wpdb->prefix . self::$activations_table; - $sql = "CREATE TABLE IF NOT EXISTS $licenses_table ( + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); + + // Create licenses table - dbDelta requires each CREATE TABLE to be called separately + $sql_licenses = "CREATE TABLE $licenses_table ( id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, license_key varchar(255) NOT NULL, product_id bigint(20) UNSIGNED NOT NULL, @@ -55,15 +58,18 @@ class LicenseManager { expires_at datetime DEFAULT NULL, created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (id), + PRIMARY KEY (id), UNIQUE KEY license_key (license_key), KEY product_id (product_id), KEY order_id (order_id), KEY user_id (user_id), KEY status (status) - ) $charset_collate; + ) $charset_collate;"; - CREATE TABLE IF NOT EXISTS $activations_table ( + dbDelta($sql_licenses); + + // Create activations table + $sql_activations = "CREATE TABLE $activations_table ( id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, license_id bigint(20) UNSIGNED NOT NULL, domain varchar(255) DEFAULT NULL, @@ -73,13 +79,12 @@ class LicenseManager { status varchar(20) NOT NULL DEFAULT 'active', activated_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, deactivated_at datetime DEFAULT NULL, - PRIMARY KEY (id), + PRIMARY KEY (id), KEY license_id (license_id), KEY status (status) ) $charset_collate;"; - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - dbDelta($sql); + dbDelta($sql_activations); } /**