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:
@@ -296,6 +296,10 @@ class CheckoutController {
|
|||||||
// Link order to new user
|
// Link order to new user
|
||||||
$order->set_customer_id($new_user_id);
|
$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
|
// Set WooCommerce customer billing data
|
||||||
$customer = new \WC_Customer($new_user_id);
|
$customer = new \WC_Customer($new_user_id);
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class Bootstrap {
|
|||||||
|
|
||||||
// Frontend (customer-spa)
|
// Frontend (customer-spa)
|
||||||
FrontendAssets::init();
|
FrontendAssets::init();
|
||||||
Shortcodes::init();
|
// Note: Shortcodes removed - WC pages now redirect to SPA routes via TemplateOverride
|
||||||
TemplateOverride::init();
|
TemplateOverride::init();
|
||||||
new PageAppearance();
|
new PageAppearance();
|
||||||
|
|
||||||
|
|||||||
@@ -252,19 +252,14 @@ class EmailRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Customer variables
|
// Customer variables
|
||||||
if ($data instanceof \WC_Customer) {
|
if ($data instanceof \WC_Customer) {
|
||||||
// Generate password reset URL for new customers
|
// Get temp password from user meta (stored during auto-registration)
|
||||||
$set_password_url = '';
|
$user_temp_password = get_user_meta($data->get_id(), '_woonoow_temp_password', true);
|
||||||
$user = get_user_by('id', $data->get_id());
|
|
||||||
if ($user) {
|
// Generate login URL (pointing to SPA login instead of wp-login)
|
||||||
$reset_key = get_password_reset_key($user);
|
$appearance_settings = get_option('woonoow_appearance_settings', []);
|
||||||
if (!is_wp_error($reset_key)) {
|
$spa_page_id = $appearance_settings['general']['spa_page'] ?? 0;
|
||||||
$set_password_url = network_site_url(
|
$login_url = $spa_page_id ? get_permalink($spa_page_id) . '#/login' : wp_login_url();
|
||||||
"wp-login.php?action=rp&key={$reset_key}&login=" . rawurlencode($user->user_login),
|
|
||||||
'login'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$variables = array_merge($variables, [
|
$variables = array_merge($variables, [
|
||||||
'customer_id' => $data->get_id(),
|
'customer_id' => $data->get_id(),
|
||||||
@@ -273,7 +268,8 @@ class EmailRenderer {
|
|||||||
'customer_last_name' => $data->get_last_name(),
|
'customer_last_name' => $data->get_last_name(),
|
||||||
'customer_email' => $data->get_email(),
|
'customer_email' => $data->get_email(),
|
||||||
'customer_username' => $data->get_username(),
|
'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')),
|
'my_account_url' => get_permalink(wc_get_page_id('myaccount')),
|
||||||
'shop_url' => get_permalink(wc_get_page_id('shop')),
|
'shop_url' => get_permalink(wc_get_page_id('shop')),
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -196,12 +196,15 @@ Your account is ready. Here\'s what you can do now:
|
|||||||
✓ Easy returns and refunds
|
✓ Easy returns and refunds
|
||||||
[/card]
|
[/card]
|
||||||
|
|
||||||
[card type="warning"]
|
[card type="success"]
|
||||||
**Important:** Please set your password to access your account:
|
**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]
|
[/card]
|
||||||
|
|
||||||
[button url="{shop_url}" style="outline"]Start Shopping[/button]
|
[button url="{shop_url}" style="outline"]Start Shopping[/button]
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ class TemplateOverride
|
|||||||
*/
|
*/
|
||||||
public static function init()
|
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)
|
// Hook to wp_loaded with priority 10 (BEFORE WooCommerce's priority 20)
|
||||||
// This ensures we process add-to-cart before WooCommerce does
|
// This ensures we process add-to-cart before WooCommerce does
|
||||||
add_action('wp_loaded', [__CLASS__, 'intercept_add_to_cart'], 10);
|
add_action('wp_loaded', [__CLASS__, 'intercept_add_to_cart'], 10);
|
||||||
@@ -93,6 +96,59 @@ class TemplateOverride
|
|||||||
}, 1);
|
}, 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
|
* Disable canonical redirects for SPA routes
|
||||||
* This prevents WordPress from redirecting /product/slug URLs
|
* This prevents WordPress from redirecting /product/slug URLs
|
||||||
|
|||||||
Reference in New Issue
Block a user