Email class
Creating a Custom Email Class
To build a custom email class in WooCommerce with YayMail, you’ll need to extend the BaseEmail
class provided by YayMail. Here’s a clear example to guide you in setting up your custom email class:
Extending BaseEmail:
Start by defining a new class that extends the BaseEmail class provided by YayMail. Make sure to include the following essential variables and methods for the class:
Variables:
id
: A unique identifier for the email.title
: The title of the email, displayed in the YayMail Editor or settings.recipient
: Specifies who receives the email (e.g., Customer or Admin).source
: An array with plugin details, such as plugin_id and plugin_name.email_types
: Defines the email type.
By following these steps, you can create a custom email template that works smoothly with your WooCommerce and YayMail setup.
- Function:
get_default_delements
The
get_default_elements
function is designed to retrieve and return a set of default elements using theElementsLoader::load_elements
method. Below is a breakdown of its components:Logo Element: A basic component identified by its type 'Logo'.
Heading Element: This element includes a 'Heading' type with specified attributes, notable for its 'rich_text' attribute containing the text 'Email Heading'.
Text Element: Main content for this email
Footer Element: A basic email footer for this email
To integrate a hook for triggering an email within the constructor, use the default method provided by the
BaseEmail
class. Alternatively, you can override this function if customization is required.Add a hook to send mail:
To return the path of the 'new-email-1.php' template, the function
get_template_file
generates the content as follows:
We have followed the steps provided, and the complete file is now
Last updated
Was this helpful?