Custom Emails
Custom Emails

Knowledge Base

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 :

  • wr_new_reward : The new reward email
  • wr_available_unlockables : The available rewards email
  • couponreminder : The coupon expiration reminder email
  • pointsreminder : The inactivity points expiration reminder email
  • wr_sponsored : The referral email
  • wr_achieved : The unlocked achievement email

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
The only part of emails you can override is the main content parts

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 :

  • head : lws_mail_head_couponreminder.
  • body : lws_mail_body_couponreminder.
  • foot : lws_mail_foot_couponreminder.

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:

  • ID (int) : the post ID in database.
  • post_title (string) : the coupon code.
  • post_content (string) : the coupon title.
  • post_excerpt (string) : the coupon description.
  • customer_email (string) : the user email the coupon is restricted to.
  • expiry_date (int) : the coupon expiry date as a unix timestamp (seconds since Epoch).
  • remind_index (int) : if several reminder deadline are set, it indicates the current step that trigger the mail. From bigger to smaller, zero is always the last step before expiry.

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); 
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
Was this article helpful?
Dislike 0
Views: 220

Continue reading

Previous: Points Hooks