feat: temp password in emails + WC page redirects to SPA

1. Temp password for auto-registered users:
   - Store password in _woonoow_temp_password user meta (CheckoutController)
   - Add {user_temp_password} and {login_url} variables (EmailRenderer)
   - Update new_customer email template to show credentials

2. WC page redirects to SPA routes:
   - Added redirect_wc_pages_to_spa() in TemplateOverride
   - Maps: /shop → /store/#/, /cart → /store/#/cart, etc.
   - /checkout → /store/#/checkout, /my-account → /store/#/account
   - Single products → /store/#/products/{slug}

3. Removed shortcode system:
   - Commented out Shortcodes::init() in Bootstrap
   - WC pages now redirect to SPA instead
This commit is contained in:
Dwindi Ramadhana
2026-01-01 16:45:24 +07:00
parent 38a7a4ee23
commit 58681e272e
5 changed files with 78 additions and 19 deletions

View File

@@ -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);

View File

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

View File

@@ -253,18 +253,13 @@ 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'
);
}
}
// 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')),
]);

View File

@@ -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]

View File

@@ -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