WooRewards sends different emails to your customers. You can customize all these emails in the emails section of the plugin. However, there are some limitations in the content you can put in these emails.
With the following documentation, you’ll see how to override WooRewards emails with your own email templates.
Email Templates
All WooRewards emails have a template name. To override an email, you need to override a particular template. The template names are as follows :
Email Structure
An email is structured like this :
- The <head> which contains an inline <style> element
- The <body> divided into 3 parts :
- the header composed of a picture, a title and a text (you can customize them in the emails section)
- the main content that depends on the email template
- the footer that you can customize on the emails page
Body Hooks
Each part has a dedicated hook composed by a prefix and the email template name. Each one expects a html code as a string. The administration settings (title, picture…) are passed as an array. The data specific to that email instance are only sent to the main content filter.
Data format depends on the email purpose (described later in the documentation).
apply_filters('lws_mail_head_' . $template_name, '', $settings)
apply_filters('lws_mail_body_' . $template_name, '', $data, $settings)
apply_filters('lws_mail_foot_' . $template_name, '', $settings)
Example
In the following example, you’ll see how to override the coupon expiry reminder email.
Hooks
To override the content, we’ll use the following hooks :
Data
The second argument passed to ‘lws_mail_body_couponreminder’ filter is an array. Each array item is a coupon. Coupons are grouped by user email and reminder index. So, one email can contain several coupons.
A coupon is an array with the following keys:
Override Mail Header
function my_coupon_reminder_head( $html, $settings )
{
return '<p>' . $settings['title']. '</p>';
}
\add_filter( 'lws_mail_head_couponreminder', 'my_coupon_reminder_body', 10, 2);
Override Mail Body
function my_coupon_reminder_body( $html, $data, $settings )
{
foreach( $data as $post )
$html .= sprintf('<p>The coupon with code <b class="code">%s</b> will expire soon.</p>', $post['post_title']);
return $html;
}
// go before, if content is already set, standard behavior do not override it
\add_filter( 'lws_mail_body_couponreminder', 'my_coupon_reminder_body', 5, 3);
Override Mail Footer
function my_coupon_reminder_foot( $html, $settings )
{
return '<p>' . $settings['footer']. '</p>';
}
\add_filter( 'lws_mail_foot_couponreminder', 'my_coupon_reminder_body', 10, 2);
Override mail inline style
function my_coupon_reminder_style( $style, $css_url, $css_option )
{
if( $css_option == 'lws_mail_template_couponreminder' )
{
$style = 'b.code{text-transform: uppercase;}';
}
return $style;
}
\add_filter( 'lws_mail_body_couponreminder', 'my_coupon_reminder_body', 20, 3); // go after, override standard style