Managing Easy Digital Downloads Email Tags
Easy Digital Downloads uses template tags to allow you to insert data into your emails. These are simply functions that output data for rendering in the email. These are the default template tags:
- {download_list} – A list of downloads with clickable links for each download purchased
Note: The Sale Notification email will not include clickable links, as those are only intended for the customer’s email receipt. - {file_urls} – A plain-text list of download URLs for each download purchased
- {name} – The buyer’s first name
- {fullname} – The buyer’s full name, first and last
- {username} – The buyer’s user name on the site, if they registered an account
- {user_email} – The buyer’s email address
- {billing_address} – The buyer’s billing address
- {date} – The date of the purchase
- {subtotal} – The price of the purchase before taxes
- {tax} – The taxed amount of the purchase
- {price} – The total price of the purchase
- {payment_id} – The unique ID number for this purchase
- {receipt_id} – The unique ID number for this purchase receipt
- {payment_method} – The method of payment used for this purchase
- {sitename} – Your site name
- {receipt_link} – Adds a link so users can view their receipt directly on your website if they are unable to view it in the browser correctly.
- {discount_codes} – Adds a list of any discount codes applied to this purchase
- {ip_address} – The buyer’s IP Address
EDD has built-in functions to help you create new tags, remove existing tags, and test to see if a given tag exists.
Adding a New Tag
Here’s an example snippet that you can use and extend as needed: https://library.wpcode.com/snippet/j578kp2g/
Removing a Tag
If you’re removing a tag you created, simply remove all the code you wrote to make it. Once the transient expires then it’ll be gone. If you want to remove a core tag, you can use something like the example below:
function edd_my_remove_tags() {
edd_remove_email_tag( 'name' );
}
add_action( 'edd_add_email_tags', 'edd_my_remove_tags', 99 );
In the example above, ‘name’ is the name of the tag. We still hook into edd_add_email_tags even though we’re removing it. Note the priority of 99. WordPress default action-hook priority is 10. By overriding that and setting it to 99, we are telling it to run after any other hooked function with a priority less than 99. If the email tag you are trying to remove happens to get added in a function with a priority higher than 99, you’ll have to increase the priority to make sure it is greater than that number – and thus runs “after” the tag is added. Essentially, you can’t remove a tag that has not been added yet.
Looking for a Tag
If you want to see if a tag exists then you can do something like this:
if ( edd_email_tag_exists( 'name' ) ) { echo "Yep!"; }
edd_email_tag_exists() returns boolean.