Don’t send emails from staging copies
On staging, development and local copies of the site, WordPress doesn’t send any email, so customers never get a test order confirmation.
<?php
add_filter(
'pre_wp_mail',
static function ( $return ) {
if ( 'production' !== wp_get_environment_type() ) {
return true; // Pretend it was sent.
}
return $return;
}
);
Good to know
Needs WP_ENVIRONMENT_TYPE set on the copy. Mail plugins that don’t use wp_mail() aren’t stopped.
In these packs
- Email: Emails from your name and address, sent through SMTP, and fewer notification emails.
- Developer tools: Maintenance mode, template names, page stats, environment labels and a WP-Cron viewer.