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.

  • if it is not hooked, it probably means you hook too late or that you do not understand the execution path. You should probably try to hook earlier (plugins_loaded) at least to check if that is the cause. – Mark Kaplun Jul 10 '17 at 11:19
  • @Mark Kaplun Thanks, I'm trying to do that. I shall leave a reply when I figure out the solution – Maria Daniel Deepak Jul 11 '17 at 2:57

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.