Easy Digital Downloads (EDD) – Purchase Receipt emails couldn’t be logged

I’m trying to log the purchase receipt email sent out by the EDD plugin, in the database. But I’m unable to do so.

The custom plugin that logs emails is hooked on to wp_loaded hook and filters all emails by the following filter.

add_filter( 'wp_mail', array( $this, 'log_email' ) );

But the purchase receipt emails are not logged.

Note: The custom plugin logs others emails sent. Example, if I use WP Mail SMTP plugin to send a test email, the email is perfectly logged into database.

I debugged to see if my hook is invoked at a later point, but I found that EDD sends the purchase receipts emails via init hook.

I further debugged and found that my plugin is not hooked into global $wp_filter var.

var_dump( $wp_filter['wp_mail'] );

Reference:
WordPress Action hook sequence

Any suggestion is greatly appreciated.

1 Answer
1

wp_loaded hook is fired after init hook.

So by the time you add your filter, the filter is already called by EDD.

You can either change your hook to init and use a high priority or use an earlier hook like plugins_loaded.

Leave a Comment