You can email the admin upon a fatal error in WooCommerce by hooking into woocommerce_shutdown_error, which fires whenever WooCommerce logs a fatal error — sending the error message, file, and line number straight to your inbox instead of only the Status > Logs screen.
Why Get Notified Immediately
- Backend fatal errors don’t always trigger WordPress’s own built-in admin email notification
- Catching a critical error minutes after it happens (instead of days later) limits how much revenue or data is affected
- WooCommerce already logs these errors — this just surfaces them proactively instead of requiring a manual check
Step 1: Email the Admin on Fatal Errors
/**
* Email the site admin whenever WooCommerce logs a fatal error.
* Test on staging first before relying on this in production.
*/
add_action( 'woocommerce_shutdown_error', 'email_admin_on_fatal_error' );
function email_admin_on_fatal_error( $error ) {
$subject = 'Critical Error on Your WooCommerce Site';
$message = sprintf(
'%1$s in %2$s on line %3$s',
$error['message'],
$error['file'],
$error['line']
);
wp_mail( get_option( 'admin_email' ), $subject, $message );
}Sending to a Different Address Than the Admin Email
add_action( 'woocommerce_shutdown_error', 'email_dev_team_on_fatal_error' );
function email_dev_team_on_fatal_error( $error ) {
$message = sprintf( '%1$s in %2$s on line %3$s', $error['message'], $error['file'], $error['line'] );
wp_mail( 'dev-alerts@example.com', 'WooCommerce Fatal Error', $message );
}Troubleshooting
Too Many Emails During a Recurring Error
If the same error fires repeatedly (e.g. on every page load from a broken plugin), you’ll get flooded with emails. Add basic throttling — check a transient before sending, and skip if an email for the same error was already sent within the last hour.
Emails Never Arrive
Test that wp_mail() itself is functioning on your server — many hosts block PHP’s default mail function, so a proper SMTP plugin is often required for reliable delivery regardless of this specific snippet.
Frequently Asked Questions
Does this replace WooCommerce’s error logs?
No, errors still get logged under WooCommerce > Status > Logs as normal — this snippet just adds an email notification on top of that existing logging.
Will this catch every type of PHP error?
It specifically targets errors WooCommerce itself logs as fatal through its own error-catching mechanism, not necessarily every possible PHP warning or notice on the site.
Should I test this on a live site?
Test on staging first — intentionally triggering a fatal error on production just to confirm the email works isn’t worth the risk.
Conclusion
Emailing the admin upon a fatal error in WooCommerce turns passive error logging into an active alert system. Add basic throttling if the underlying issue is recurring, so you get notified without your inbox being flooded.
See also How to Fix Call to Undefined Function wc_get_order Error. Then read How to Fix the upload_max_filesize Error in WooCommerce.
Prefer no code? All-in-One Utilities is a free plugin, so you can harden and speed up WordPress without code.