diff --git a/includes/Api/CheckoutController.php b/includes/Api/CheckoutController.php index 560765a..00ac741 100644 --- a/includes/Api/CheckoutController.php +++ b/includes/Api/CheckoutController.php @@ -296,6 +296,10 @@ class CheckoutController { // Link order to new user $order->set_customer_id($new_user_id); + // Store temp password in user meta for email template + // The real password is already set via wp_insert_user + update_user_meta($new_user_id, '_woonoow_temp_password', $password); + // Set WooCommerce customer billing data $customer = new \WC_Customer($new_user_id); diff --git a/includes/Core/Bootstrap.php b/includes/Core/Bootstrap.php index b97f553..164e865 100644 --- a/includes/Core/Bootstrap.php +++ b/includes/Core/Bootstrap.php @@ -45,7 +45,7 @@ class Bootstrap { // Frontend (customer-spa) FrontendAssets::init(); - Shortcodes::init(); + // Note: Shortcodes removed - WC pages now redirect to SPA routes via TemplateOverride TemplateOverride::init(); new PageAppearance(); diff --git a/includes/Core/Notifications/EmailRenderer.php b/includes/Core/Notifications/EmailRenderer.php index 4b6b410..4eb6bad 100644 --- a/includes/Core/Notifications/EmailRenderer.php +++ b/includes/Core/Notifications/EmailRenderer.php @@ -252,19 +252,14 @@ class EmailRenderer { } // Customer variables - if ($data instanceof \WC_Customer) { - // Generate password reset URL for new customers - $set_password_url = ''; - $user = get_user_by('id', $data->get_id()); - if ($user) { - $reset_key = get_password_reset_key($user); - if (!is_wp_error($reset_key)) { - $set_password_url = network_site_url( - "wp-login.php?action=rp&key={$reset_key}&login=" . rawurlencode($user->user_login), - 'login' - ); - } - } + if ($data instanceof \WC_Customer) { + // Get temp password from user meta (stored during auto-registration) + $user_temp_password = get_user_meta($data->get_id(), '_woonoow_temp_password', true); + + // Generate login URL (pointing to SPA login instead of wp-login) + $appearance_settings = get_option('woonoow_appearance_settings', []); + $spa_page_id = $appearance_settings['general']['spa_page'] ?? 0; + $login_url = $spa_page_id ? get_permalink($spa_page_id) . '#/login' : wp_login_url(); $variables = array_merge($variables, [ 'customer_id' => $data->get_id(), @@ -273,7 +268,8 @@ class EmailRenderer { 'customer_last_name' => $data->get_last_name(), 'customer_email' => $data->get_email(), 'customer_username' => $data->get_username(), - 'set_password_url' => $set_password_url, + 'user_temp_password' => $user_temp_password ?: '', + 'login_url' => $login_url, 'my_account_url' => get_permalink(wc_get_page_id('myaccount')), 'shop_url' => get_permalink(wc_get_page_id('shop')), ]); diff --git a/includes/Email/DefaultTemplates.php b/includes/Email/DefaultTemplates.php index 21d1c31..0ce7607 100644 --- a/includes/Email/DefaultTemplates.php +++ b/includes/Email/DefaultTemplates.php @@ -196,12 +196,15 @@ Your account is ready. Here\'s what you can do now: ✓ Easy returns and refunds [/card] -[card type="warning"] -**Important:** Please set your password to access your account: +[card type="success"] +**Your Login Credentials:** -[button url="{set_password_url}" style="solid"]Set Your Password[/button] +📧 **Email:** {customer_email} +🔑 **Password:** {user_temp_password} -This link expires in 24 hours. If expired, use "Forgot Password?" on the login page. +[button url="{login_url}" style="solid"]Log In Now[/button] + +We recommend changing your password in Account Settings after logging in. [/card] [button url="{shop_url}" style="outline"]Start Shopping[/button] diff --git a/includes/Frontend/TemplateOverride.php b/includes/Frontend/TemplateOverride.php index 2b2ad10..ffce643 100644 --- a/includes/Frontend/TemplateOverride.php +++ b/includes/Frontend/TemplateOverride.php @@ -13,6 +13,9 @@ class TemplateOverride */ public static function init() { + // Redirect WooCommerce pages to SPA routes early (before template loads) + add_action('template_redirect', [__CLASS__, 'redirect_wc_pages_to_spa'], 5); + // Hook to wp_loaded with priority 10 (BEFORE WooCommerce's priority 20) // This ensures we process add-to-cart before WooCommerce does add_action('wp_loaded', [__CLASS__, 'intercept_add_to_cart'], 10); @@ -93,6 +96,59 @@ class TemplateOverride }, 1); } + /** + * Redirect WooCommerce pages to SPA routes + * Maps: /shop → /store/#/, /cart → /store/#/cart, etc. + */ + public static function redirect_wc_pages_to_spa() + { + // Get SPA page URL + $appearance_settings = get_option('woonoow_appearance_settings', []); + $spa_page_id = $appearance_settings['general']['spa_page'] ?? 0; + + if (!$spa_page_id) { + return; // No SPA page configured + } + + // Already on SPA page, don't redirect + global $post; + if ($post && $post->ID == $spa_page_id) { + return; + } + + $spa_url = trailingslashit(get_permalink($spa_page_id)); + + // Check which WC page we're on and redirect + if (is_shop()) { + wp_redirect($spa_url . '#/', 302); + exit; + } + + if (is_product()) { + global $product; + if ($product) { + $slug = $product->get_slug(); + wp_redirect($spa_url . '#/products/' . $slug, 302); + exit; + } + } + + if (is_cart()) { + wp_redirect($spa_url . '#/cart', 302); + exit; + } + + if (is_checkout() && !is_order_received_page()) { + wp_redirect($spa_url . '#/checkout', 302); + exit; + } + + if (is_account_page()) { + wp_redirect($spa_url . '#/account', 302); + exit; + } + } + /** * Disable canonical redirects for SPA routes * This prevents WordPress from redirecting /product/slug URLs