fix: email buttons now render with inline styles for Gmail
1. EmailRenderer: Added button parsing with full inline styles
- Buttons now use table-based layout for email client compatibility
- Solid and outline button styles with custom colors from settings
2. DefaultTemplates: Updated new_customer template
- Added 'Set Your Password' button for auto-registered users
- Uses {set_password_url} variable for password reset link
3. EmailRenderer: Added set_password_url variable
- Generates secure password reset link for new customers
- Also added my_account_url and shop_url to customer variables
This commit is contained in:
@@ -250,6 +250,19 @@ 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'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$variables = array_merge($variables, [
|
||||
'customer_id' => $data->get_id(),
|
||||
'customer_name' => $data->get_display_name(),
|
||||
@@ -257,6 +270,9 @@ 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,
|
||||
'my_account_url' => get_permalink(wc_get_page_id('myaccount')),
|
||||
'shop_url' => get_permalink(wc_get_page_id('shop')),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -337,10 +353,49 @@ class EmailRenderer {
|
||||
|
||||
// Get email customization settings for colors
|
||||
$email_settings = get_option('woonoow_email_settings', []);
|
||||
$primary_color = $email_settings['primary_color'] ?? '#7f54b3';
|
||||
$secondary_color = $email_settings['secondary_color'] ?? '#7f54b3';
|
||||
$button_text_color = $email_settings['button_text_color'] ?? '#ffffff';
|
||||
$hero_gradient_start = $email_settings['hero_gradient_start'] ?? '#667eea';
|
||||
$hero_gradient_end = $email_settings['hero_gradient_end'] ?? '#764ba2';
|
||||
$hero_text_color = $email_settings['hero_text_color'] ?? '#ffffff';
|
||||
|
||||
// Parse button shortcodes with FULL INLINE STYLES for Gmail compatibility
|
||||
// Format: [button url="..." style="solid|outline"]Text[/button]
|
||||
$content = preg_replace_callback(
|
||||
'/\[button\s+url=["\']([^"\']+)["\'](?:\s+style=["\']?(solid|outline)["\']?)?\]([^\[]+)\[\/button\]/',
|
||||
function($matches) use ($primary_color, $secondary_color, $button_text_color) {
|
||||
$url = $matches[1];
|
||||
$style = $matches[2] ?? 'solid';
|
||||
$text = trim($matches[3]);
|
||||
|
||||
if ($style === 'outline') {
|
||||
// Outline button - transparent background with border
|
||||
$button_style = sprintf(
|
||||
'display: inline-block; background-color: transparent; color: %s; padding: 14px 28px; border: 2px solid %s; border-radius: 6px; text-decoration: none; font-weight: 600; font-family: "Inter", Arial, sans-serif; font-size: 16px; text-align: center; mso-padding-alt: 0;',
|
||||
esc_attr($secondary_color),
|
||||
esc_attr($secondary_color)
|
||||
);
|
||||
} else {
|
||||
// Solid button - full background color
|
||||
$button_style = sprintf(
|
||||
'display: inline-block; background-color: %s; color: %s; padding: 14px 28px; border: none; border-radius: 6px; text-decoration: none; font-weight: 600; font-family: "Inter", Arial, sans-serif; font-size: 16px; text-align: center; mso-padding-alt: 0;',
|
||||
esc_attr($primary_color),
|
||||
esc_attr($button_text_color)
|
||||
);
|
||||
}
|
||||
|
||||
// Use table-based button for better email client compatibility
|
||||
return sprintf(
|
||||
'<table role="presentation" border="0" cellpadding="0" cellspacing="0" style="margin: 16px auto;"><tr><td align="center"><a href="%s" style="%s">%s</a></td></tr></table>',
|
||||
esc_url($url),
|
||||
$button_style,
|
||||
esc_html($text)
|
||||
);
|
||||
},
|
||||
$content
|
||||
);
|
||||
|
||||
$class = 'card';
|
||||
$style = 'width: 100%; background-color: #ffffff; border-radius: 8px;';
|
||||
$content_style = 'padding: 32px 40px;';
|
||||
|
||||
Reference in New Issue
Block a user