Home / Admin / Sample Email Template Tag
Duplicate Snippet

Embed Snippet on Your Site

Sample Email Template Tag

This is an example of how to register a new email template tag for EDD as of version 3.3.0. Intended to be modified.

Code Preview
php
<?php
/**
 * Register a custom email tag.
 *
 * @return void
 */
function prefix_add_sample_email_tag() {
	edd_add_email_tag(
		'custom_email_tag', // Tag
		'This is a custom email tag!', // Description
		'prefix_render_sample_email_tag', // Callback
		'Custom Email Tag', // Label
		array( 'order' ), // Optional contexts. `order` is the default.`
		array( 'customer' ) // Optional recipients. Omit to allow this to be used in any email. Options can include customer, admin, user.
	);
}
add_action( 'edd_add_email_tags', 'prefix_add_sample_email_tag' );
/**
 * Render the custom email tag (requires EDD 3.3.0).
 *
 * @param int    $email_object_id              The email object ID.
 * @param EDD\Emails\Types\Email $email_object The email object. This could be an order, license, user, etc.
 * @param string $context                      The context of the email. This could be order, license, user, etc.
 *
 * @return string
 */
function prefix_render_sample_email_tag( $email_object_id, $email_object = null, $email = null ) {
	if ( 'order' === $email->context ) {
		return $email_object->currency;
	}
	return 'This is not an order email.';
}

Comments

Add a Comment